shemp has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.# 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
Is the way i am planning on structuring this UtilLib a good way to do it, or should i be doing something fundamentally different?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Good Module Design
by dragonchild (Archbishop) on May 26, 2005 at 19:11 UTC | |
by derby (Abbot) on May 26, 2005 at 19:46 UTC | |
by shemp (Deacon) on May 26, 2005 at 20:05 UTC | |
|
Re: Good Module Design
by bart (Canon) on May 27, 2005 at 07:05 UTC | |
by shemp (Deacon) on May 31, 2005 at 20:32 UTC |