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


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to Questions about sharing code by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.