Forgive my naiveté but have found conflicting opinions on the following topic. I am attempting to make use of CGI::Application and OOP on a project but feel as though I am hanging myself with all the freedom that Perl provides.

For the (procedural) projects I have worked on in the past, a module has been set up with common methods used throughout the application via Export. My question is, when structuring an application (made up of smaller applications) what is the best procedure for sharing a basic set of methods. These methods aren't to be overridden or refined ... just used by the separate application modules. I have seen this accomplished in several ways:

1) Set up a Base C::A module / class that @ISA CGI::Application. This Base class implements sub setup{ ... } and the standard set of C::A methods and is used by all other C::A modules (providing access to the default set of C::A methods as well as any common (custom) methods through inheritance). This seems like a good way to share common run-modes maybe, but not utility style methods.

2) Set up a Base class (Super / Abstract class) to share methods through inheritance despite the fact that the relationship between the base and subclasses isn't one of inheritance ... just utility.

3) Set up a "utility" class to be 'use'd by the C::A modules (any any custom classes) providing access to the common methods.

I hope I explained that clearly enough ... I know that all three are somewhat similar but I am looking for the 'cleanest' way of doing it.

Also, if you think I am wasting my time trying to share a somewhat mismatched group of methods and should be breaking these methods up into respective classes (ie: a Display class that handles template output, pagination display, etc. / Authentication class that handles user auth, session management, etc. / a Debug class that provides Dumper and various diagnostics) please let me know. I am teetering back and fourth on that as well.

Thank you all ahead of time ... I appreciate the help.

- junior monk

author => jeyroz


In reply to Code reuse and method sharing with OOP / CGI::Application by jeyroz

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.