[cgiapp] Program format (this is the way I write my code -help?)

Barry Moore barry.moore at genetics.utah.edu
Wed Feb 13 23:07:49 EST 2008


Lou,

If your program was 10K lines long, then I'm guessing that there were  
a lot of different actions, and maybe a lot of html included in your  
code?  If you start to rewrite this with CGI::Application you might  
want to think about clustering those actions into smaller groups and  
making several smaller "applications" that work together as a suite  
for form your larger game.  For instance all of the actions  
associated with login could be one "application", while all of the  
actions associated with moving through the rooms in the dungeon (or  
whatever) could be associated with another "application".  This will  
break your code up into more manageable bits.

And if you have html strewn through your perl code, CGI::Application  
will make it easy for  you to adopt a html template language like  
HTML::Template or Template Toolkit which will get all of the html out  
of you code.  Google around for MVC frameworks and you'll see that  
CGI::Application and many other web application frameworks are trying  
to make it easy to separate the logic of your coding language (perl)  
from the presentation of you display language (html)  which makes  
your code more flexible and maintainable.

If you're being exposed to object oriented perl for the first time  
I'd recommend the first few chapters of the Object Oriented Perl book  
by Damain Conway (http://www.manning.com/conway/).

Barry

On Feb 13, 2008, at 5:33 PM, Lou Hernsen wrote:

> I sorta understand....and then not..
>
> The last program I wrote was 10K+ line long where I used only  
> subroutines
> all in one cgi....
> I was told I was nuts for doing that... now I am rewritting  
> everything over
> again... and using some
> new things I have learned about.... I will google some of the words  
> you used
> .. and see what i get.
>
> Is what your talking about called "object oriented"?
>
> thanks for the help...
> still lost but looking :)
> Lou
>
>
> ----- Original Message -----
> From: "Stewart Heckenberg" <stewart.heckenberg at gmail.com>
> To: "CGI Application" <cgiapp at lists.openlib.org>
> Sent: Wednesday, February 13, 2008 7:29 PM
> Subject: Re: [cgiapp] Program format (this is the way I write my
> code -help?)
>
>
>> Hi Lou,
>>
>> Actually you're close, but not close enough :)
>>
>> cgiapp actually allows you to get rid of all your if/else logic and
>> instead use what are called "run modes", which in terms of your games
>> are all the action/packets, e.g. instead of:
>>
>>  if ($Input{Action} eq "Log In")
>>
>> you would use:
>>
>> sub login {...
>>
>> and to trigger that sub to run, you set a query parameter called "rm"
>> to be "login", e.g. foo.cgi?rm=login
>>
>> That's how cgiapp works -- instead of if/else blocks for your logic,
>> you use subs, and to execute a particular sub you merely set the rm
>> param to be the name of that runmode/sub. Have a look at the cgiapp
>> documentation for some examples.
>>
>> Hope this helps :)
>>
>> Kind regards,
>> Stew
>>
>> On 14/02/2008, Lou Hernsen <lhernsen1015 at wowway.com> wrote:
>>> Hallo
>>> I am writing an online game. I have a main .cgi and am using  
>>> packages
> which
>>> are "required" as needed.
>>> My .cgi is one long if-elsif-else all based on what action you  
>>> make in
> the
>>> game. I do it this way so I can complete one packet at a time to  
>>> do a
>>> certain thing.
>>> All files are read in the .cgi and vars passes to packages as
> needed..... am
>>> I even close in my method?
>>>
>>>>>>>> Mind you, this is a hobby to me.. all self taught....<<<<<<<
>>>
>>> ANY suggestion for books on program format would be helpfull..  
>>> thanks
>>> comments welcome.. try not to grind me into the dust, please LOL
>>> thanks
>>> Lou
>>>
>>> here is an example.
>>>
>>>  if ($Input{Action} eq "Log In")
>>>  {
>>>   $Pm{Status}=Login::LogIn("$Input{Name}","$Input{PW}");
>>>   exit;
>>>  }
>>>  elsif ($Input{Action} eq "New Player")
>>>  {
>>>   Login::NewPlayer();
>>>   exit;
>>>  }
>>>  elsif ($Input{Action} eq "Create Player")
>>>  {
>>>   Login::CreatePlayer("$Input{Name}","$Input{PW},"$Input{Gender}";
>>>   exit;
>>>  }
>>>  elsif ($Input{Action} eq "EmailLogin")
>>>  {
>>>   $Pm{Status}=Login::EmailLogin("$Input{Name}","$Input{SN}");
>>>   exit;
>>>  }
>>>
>>>
>>> #####  CGI::Application community mailing list  ################
>>> ##                                                            ##
>>> ##  To unsubscribe, or change your message delivery options,  ##
>>> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
>>> ##                                                            ##
>>> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
>>> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
>>> ##                                                            ##
>>> ################################################################
>>>
>>>
>>
>> #####  CGI::Application community mailing list  ################
>> ##                                                            ##
>> ##  To unsubscribe, or change your message delivery options,  ##
>> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
>> ##                                                            ##
>> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
>> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
>> ##                                                            ##
>> ################################################################
>>
>>
>>
>> --
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.5.516 / Virus Database: 269.20.4/1275 - Release Date:  
>> 2/12/08
> 3:20 PM
>>
>>
>
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
>



More information about the cgiapp mailing list