Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Organising big CGI::Application codebases

by themage (Friar)
on Sep 05, 2008 at 10:13 UTC ( #709227=note: print w/ replies, xml ) Need Help??


in reply to Organising big CGI::Application codebases

zby,

I'm not sure what you mean when you say that your whole application is just one object and the runmodes it's methods. But I will agree with you for the moment. And illustrate what I think is your point.

I like the main code for my bigger applications to be:

use App::Class; App::Class->new()->run();
And then, inside my application any external interface with the application is done calling App::Class methods. That means, obviously, that all my run modes are methods of my class.

But I will not write all the code for my application. I'll use code others (or myself) did writen in other instances. Code for specific functions.

For instance, I'll use a module I had written that extends Config::Tiny. See the readconfig for App::Class:
use Config::myTiny; sub readconfig { my $self=shift; my $cfg=$0; $cfg=~s/\.pl$/.ini/; my $conf=Config::myTiny->read($cfg); $conf=Config::myTiny->new() unless $conf; $self->{config}=$conf; }
Now, whener I need to get a config variable, I'll use $self->{config} like this:
sub run { my $self=shift; $self->readconfig(); # ... if ($self->{config}->get('options','showonstartup')) { $self->show_mainwindow(); } # ... }


So, you application will be a single class, but you should break your code to create smaller complete and independent objects, that you will use in the code for your main application.

OoP allow you other things also. If you have (or intent to have) several application that use identical functionalities as their base, you can create a base class that implement those functions and extend that using it as base for every other application.

I think that this are the most simple and easier ways to use OoP that can help you reduce your codebase, improve your code, as the code you reuse frequently will tend be corrected faster (assuming you use the same code, not that you copy it from project to project), and get your applications running faster.

Remember...
  • use base qw(Your::Base::App);
  • if you can isolate something, you can turn it into an object



Comment on Re: Organising big CGI::Application codebases
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://709227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-09-03 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls