So today i decided that i am not going to write any more code that avoids certain design / style issues that i have consciously avoided in the past. So i've spent most of the day reading various docs about good module design, etc. Its been an eye-opening day in any case.

Im currently focusing on using modules (to be use'd) for support function libraries, instead of require'd by the scripts that want them.

I have read through most of the Jose's Guide for creating Perl modules, but thats more for writing pretty massive modules, and doesnt address some of the nitpicky things i want to deal with.
I've also reread and considered various wisdom contained in my thread constants in multiple libraries

Im trying to figure out how to best deal with other support libraries that i want included with them. For instance i have a couple general function libraries that are wrappers for DBD::MySQL, which will want to be utilized by some specific libraries i'm working on writing.

So lets say im writing a module called UtilLib.pm, and it wants to require mysql_wrapper_lib.pl, but i cant decide the best way to do this. My concern is over the idea of including the base library, and how its functions will be referenced.

Basically the file UtilLin.pm will look like this:

# require outside the package so that its functions are # NOT imported into the UtilLib namespace, so that other # libraries can use them. require mysql_wrapper_lib.pl; package UtilLib; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'public_constants' => [ qw(...) ], ... ); sub do_something { ... } # etc
So then, in any code in UtilLib, if i want to use functions in mysql_wrapper_lib.pl, i'll need to preface their names with main:: i.e. main::safe_query_execute() - otherwise perl will try to find safe_query_execute() in UtilLib.
But, i've seen it said here & there that that is bad practice. That idea is the core of this post. Complex tools are built upon more basic tools, so i am having trouble resolving how i should code in situations like this.

Is the way i am planning on structuring this UtilLib a good way to do it, or should i be doing something fundamentally different?


In reply to Good Module Design by shemp

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.