http://qs1969.pair.com?node_id=709227


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...