Re: How to avoid circular module dependencies within a distribution?

[email protected] (David Christensen)
Newsgroups perl.module-authors
Message-ID <[email protected]>
On 10/17/2016 11:05 PM, David Christensen wrote:
> I have applied a hierarchical module dependency architecture to avoid
> circular dependencies:
> 
> 1.  Modules and test scripts that do not depend upon any other
> modules within the distribution are "dependency level 0".
> 
> 2.  Modules and test scripts that depend only upon level 0 modules
> are level 1.
> 
> 3.  Modules that depend only upon levels 0 through N are level N+1.

Pondering this some more, here is a more accurate statement of the
strategy I have been using to avoid circular dependencies within
distributions (revised rules marked with '*'):

1.  Modules that do not depend upon any other modules within the
distribution are "dependency level 0".

*2.  Modules that depend only upon modules of levels 0 through N-1 are
level N, for levels N=1 and higher.

*3.  Module test scripts shall not depend upon modules of higher level
than the module they are testing.

*4.  Test scripts shall be run in order from lowest to highest level.


It's rule #3 that has been giving me the most trouble.  For example, I
have testing modules up to level 5 that I would like to use when testing
modules of level 0-4.  Rule #3 blocks me.


As I code my test scripts with no outgoing dependencies -- e.g. I do not
'use' or require' test script files in other files -- test scripts
cannot create circular dependencies.  The fact that they are named after
a particular module is for my benefit; but accidental as far as the
tools are concerned.  The file name of a test script has no bearing upon
its dependency level.


So, perhaps rule #3 should be revised.  Here is the proposed strategy:

1.  Modules that do not depend upon any other modules within the
distribution are "dependency level 0".

2.  Modules that depend only upon modules of levels 0 through N-1 are
level N, for levels N=1 and higher.

*3.  Test scripts have a level equal to the highest level module they
depend upon.

4.  Test scripts shall be run in order from lowest to highest level.


I would then write multiple test scripts for each module -- "early" test
scripts of the same level as the module under test and "late" test
scripts that depend upon higher level modules.


Comments are welcome.


David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.