[cgiapp] code reuse.
James.Q.L
shijialeee at yahoo.com
Thu Mar 13 23:55:56 EDT 2008
Greetings,
I would like to seek opinions on the issue of reusing code. i am slowly finding common things that
i need to do within my C::A apps. i have put the common codes into C::A plugin or just normal
module but i don't really like the way it is organized.
one example is that there is event logging in every apps so i created a C::A::P::EventLogging,
then in my app's Base module i have something like the following. btw, Company is the top
namespace for shared libraries used or will be used in multiple apps.
package MyAPP::Base;
use Company::CAP::EventLogging;
use Company::Util;
use MyAPP::DB;
sub cgiapp_prerun {
my $dbh = MyApp::DB->dbh;
my $uuid = Company::Util->uuid( { dbh => $dbh,
uname => $ENV{REMOTE_USER},
} );
$self->param('uuid', $uuid);
$self->elog_config( { dbh => $dbh,
uuid => $uuid,
} );
# then i can do
$self->elog("blabla");
}
two things that i don't like the above code are
1. passing $dbh to every shared lib that needs it. the $dbh is coming from each app's MyAPP::DB
module.
2. $uuid (there are other properties too) is used in other places (controller and model ) in the
app as well. in controller i just call $self->param to get it but for controller i have to pass
it as an extra parameter.
i can't think of a good way to tackle my issues.. what's your opinion?
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
More information about the cgiapp
mailing list