in reply to Help with objects.

In addition to other suggestions above, if your configuration is going to always be the same for a given script, you could consider making it a singleton object. Then the constructor for TestClass could create a private configuration object without it having to be explicitly passed in.

package ConfigFile; my $self; sub new { if ( ! defined $self ) { my $that=shift; my $class=ref($that) || $that; $self = { Verbose => 1, RaiseErrors => 0}; bless $self, $class; } return $self; } sub get_conf { my $self=shift; my $param=shift; my $result; # get result return $result; } 1;
package TestClass; require ConfigFile; sub new { my $that=shift; my $class=ref($that) || $that; my $self={ Verbose => 1, RaiseErrors => 0, Config => ConfigFile->new() }; bless $self, $class; return $self; } sub anything { my $self=shift; # Access config via $self->{Config}->get_conf() return; } 1;

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.