I seem to have painted myself into a bit of a corner here while developing some library modules. I'm not sure I understand the basics of modules well enough to work my way through this. Basically, I have a set of modules that serve as a library for a suite of programs. On problem is that I have two of these library modules that require each at least one (not related) function from the other.
It works but doesn't feel clean to me. Like an accident waiting to happen. I have always been uncomfortable with the design but don't quite know how to alleviate it. This node,
Circular usage has only served to heighten feelings of disquiet.
My questions first (then background)
Are there better ways to structure these libraries so that they do not have to reference each other?
Does it matter (in terms of system resources) how many functions are contained in a module if a program only imports a couple of functions?
Is there any harm/advantage associated with requiring/using a module inside another module? at the head of a file? in the specific function that requires it?
Are there any advantages/disadvantages to having one large (many functioned) module over several smaller modules?
For some background. I have a suite of programs that processes a set of data. Each of the eight or nine programs in this suite operate on the same data set but do different things. Some are ETL programs, others are analysis and reporting and some are system maintenance programs.
Basically, I have a library of general functions (around twenty) (Gen.pm) that perform routine actions used by the various parts of system. For example, converting three atomic fields into one compound field. Individual data elements are grouped in logical blocks and there are checks to see if a particular block is blank, some constants and general purpose variables, that sort of thing. At least one general function requires a format validation which is contained in the Spec.pm library
The next library contain specific validation functions (a few hundred) (Spec.pm) which enforce a standard on individual data elements. Natually, one of the validations has a requirements if a block is blank which is determined by a function in the Gen.pm library. and so on ...
Not every program uses these functions at the same time so that one program might export the function in Spec.pm that requires Gen.pm and not export the other function in Gen.pm that requires Spec.pm. Other programs export the lot from both libraries.
I have been thinking about just combining both libraries into one and letting it go at that but I don't really know the advantage/disadvantages involved. One complication is that I will soon be implimenting another round of validations that will have to run in parallel with the first but which will be significantly different. Now I have a third module with approx 600 functions. These specs will likely reference both Gen.pm and Spec.pm.
Any thoughts will be most appreciated :o)
Update:Many thanks for the great ideas. Funny that abstracting the dependent function out into a base library never occurred to me.
Another alternative occurred to me last night. I could just move the entirety of Gen.pm into Spec.pm. To avoid rewriting the programs that require it, I could cast Gen.pm as a wrapper module that exports the needed functions from Spec.pm. Does anyone have any experience with that kind of setup? I still have the issue of a module (Spec.pm) with a few hundred functions it it. If that is an issue at all? What exactly is the effect on program size and resource usage of such a module?
PJ
use strict; use warnings; use diagnostics;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.