Fellow Monasterians,
I was reading an old node called What shortcuts can I use for linking to other information? and it raised more questions.
In my earlier days as a Perl coder I used what perlmod calls a "tradition non-OO module" to share code. I never understood all the "EXPORTing" stuff, and all the typing of subroutine names was tedious, but the approach worked fine.
For the past few years I've used CGI::Application exclusively for all my web applications (95% of what I use Perl for), and have been using a "simplified" approach of use base qw(SomeModule), which works well and is easier on the wrist.
My question is simply, are there any caveats/ramifications to abandoning the non-OO method and exclusively using the "OO-inherited-class" module (for want of a better name)? Pluses? Minuses?
Some simplified examples:
PREVIOUSLY USED METHOD
#common routines to share among all modules package Common; use strict; use Exporter; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); *import= \&Exporter::import; @EXPORT = (); @EXPORT_OK = qw(get_today get_setup); %EXPORT_TAGS = ( All => [qw(&get_today &get_setup)]); sub get_today { #get date } sub get_setup { #get application parameters } 1; #example of a calling module package SomeFile1; use strict; use Common qw(:All); #...CGI::Application setup, etc... sub initialize { my $self = shift; my $day = $self->get_today(); my $setup = $self->get_setup(); } 1;
NEWER METHOD
#code to share package Super; use strict; use base 'CGI::Application'; sub get_today { #get date } sub get_setup { #get application parameters } 1; #example of calling module package SomeFile1; use strict; use base 'Super'; #...CGI::Application setup, etc... sub initialize { my $self = shift; my $day = $self->get_today(); my $setup = $self->get_setup(); } 1;
Thanks in advance
In reply to Questions about sharing code by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |