I think you'll need to give a small bit of sample code to demonstrate what your problem is; I'm understanding some of your general problems, but it won't be clear which solutions might help without knowing more details.

The library file can export functions using Exporter, and another module can import them and they will be available as methods. It's not a problem if multiple modules all do this, and you can tell what class the method is called from by the first parameter passed in, which will be the name of the class. Here's some sample code:

#!/usr/bin/perl use warnings; use strict; package TestBase; use base 'Exporter'; our @EXPORT_OK = qw(new do_this); sub new { warn "Calling Test1::new\n"; bless {}, shift; } sub do_this { my $self = shift; warn "doing_this to $self\n"; } package Test1; TestBase->import(qw(new do_this)); package Test2; TestBase->import(qw(new do_this)); package main; my $obj1 = Test1->new(); $obj1->do_this(); my $obj2 = Test2->new(); $obj2->do_this();

You can also re-export symbols you have imported, if you need to do that for some reason. Doing this along with inheritance should allow you to inherit both methods and library functions. For example:

#!/usr/bin/perl use warnings; use strict; package TestBase; use base 'Exporter'; our @EXPORT_OK = qw(do_this); sub do_this { my $self = shift; warn "doing_this to $self\n"; } package Test1; TestBase->import(qw(do_this)); use base 'Exporter'; our @EXPORT_OK = (@TestBase::EXPORT_OK); package main; Test1->import(qw(do_this)); do_this("some string");

Generally, a Perl object will keep all of its data in a hash or array, so having do_this change a field in the object instead of a global variable might help some of your problems.

Hope that's helpful!


In reply to Re: Arcitectural considerations with modules by sgifford
in thread Arcitectural considerations with modules by Anonymous Monk

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.