in reply to Re^2: Packaging up my code sensibly
in thread Packaging up my code sensibly

I think you will find it useful to become acquainted with Exporter, which is one of Perl's standard mechanisms for facilitating code sharing (basically it streamlines the process of importing identifiers from different namespaces, so that you don't need to prepend their package names).

Other than this, I couldn't answer your question in a node of "reasonable length" (though a more knowledgeable monk might; after all, economy is a mark of mastery). I think that a book-length treatment of modules and/or OO in Perl (like the Alpaca book or Object Oriented Perl) would be the place to look for answers.

As far as your sharing your config data, if I wanted to keep things as simple as you have them, one possibility (which is similar to wazoox's proposal but without the singleton idea from OO design) is to use a hash to hold all the config info, along with a barebones accessor for it.

# home.conf package MyPackage; my %config = ( WIKI_TITLE => 'MyWiki', DEFAULT_TARGET => 'WelcomeToMyWiki', DEFAULT_ACTION => 'view', # etc. ); sub get_config { return %config; } 1;

The code that needs this config info would then do this:

require 'home.conf'; # I'm not crazy about this name # ... my %config = MyPackage::get_config(); # copy of original hash my $frobozz = foobar( $config{ WIKI_TITLE } );
A simple variant of this would be to define a generic accessor for configuration parameters:
package MyPackage; my %config = ( # as before ); sub config { my $config_param = shift; if ( defined $config{ $config_param } ) { return $config{ $config_param }; } else { die "Unknown configuration parameter: $config_param"; } } 1;
...and the calling code would be something like:
require 'home.conf'; # ... my $frobozz = foobar( MyPackage::config( 'WIKI_TITLE' ) );
If you want to avoid the nuisance of prepending 'MyPackage::' before the name of the config function without fiddling with Exporter, you can do this:
require 'home.conf'; # ... *config = \&MyPackage::config; # make an alias my $frobozz = foobar( config( 'WIKI_TITLE' ) );
TMTOWTDI, indeed... (In fact, I suspect that better ways to do this without introducing too much complexity will not be long in coming.)

BTW, all the code above is largely untested. I'm presenting it as code as a way to convey the basic ideas. Make sure you test whatever you end up using.

the lowliest monk