in reply to how to make a universally inherited method?
I agree with IlyaM, a singleton makes more sense for this. A singleton is an object that can only be instantiated once -- successive requests for a new object just return the same one.
The Class::Singleton module probably has one of the highest POD-to-code ratios on CPAN, but it's very useful.
Your config module:
package My::Config; use strict; use base qw( Class::Singleton ); sub _new_instance { my ( $class ) = @_; my %data = ( var1 => 'This is var1', var2 => [ 'This', 'is', 'var2' ], ); return bless( \%data, $class ); } 1;
And you can use it:
my $conf = My::Config->instance; print "Config for var1 is $conf->{var1}\n";
Easy! Good luck.
Chris
M-x auto-bs-mode
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: how to make a universally inherited method?
by exphysicist (Sexton) on Nov 29, 2001 at 10:17 UTC |