[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] code reuse.


On Thu, Mar 13, 2008 at 8:55 PM, James.Q.L <suppressed> wrote:
>  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.

1. You're storing $dbh and $uuid as a param in C::A. Why are you
passing them as parameters instead of retrieving them from param?

You can also use C::A::Plugin::Stash which is like a front-end to
C::A's param method. It makes it easier to use (IMO) because it feels
like you're working directly with a variable (not a method).

2. $uuid needs to be specific to this instance. But, $dbh might fit
better in cgiapp_init, and stored as a class variable (of your
package) so that, if you use some form persistence (mod_perl,
fcgi/fastcgi, speedyCGI/persistentPerl/perperl) you'd only load and
connect once. (But, you have to handle errors and reconnections due to
timeouts.).

3. Since you haven't made the step (yet) to make "Company::Util" an
object, you could let it  store $uuid in its own namespace (as an
"our" variable?) and then access it directly wherever needed
($Company::Util::uuid). That's probably not the best practice. But,
it's part of the evolution from subroutines to objects (which I think
is the path you're on).

I went through this 4-5 years ago. I asked about it on Perlmonks
because it's more of a general Perl/style topic. I was told that I was
going through a normal transition from collecting related routines
into subroutines, into namespaces (modules) and finally objects. It's
still not always clear to me where things belong.

Mark

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.