open(my $pfh, ">&", "STDOUT") or die("$0:ERROR Unable to redirect output to STDOUT. ERR: $?/$!\n");
my %conf = (
maxchilds => '20',
waitforchilds => '180',
mhandle => $pfh,
);
print Dumper \%conf;
my $fmo = fmanager->new(\%conf);
print Dumper $fmo;
$fmo->set_mhandle($pfh);
print Dumper $fmo;
####
sub new {
my $class = shift;
my $self = {};
my %childs;
$self = {
_handle => undef,
_childs => \%childs,
waitforchilds => '120',
maxchilds => '10',
mhandle => undef,
};
bless($self,$class);
if (@_){
my $hash_ref = shift;
if ( ref($hash_ref) eq "HASH"){
while ( my ($k,$v) = ( each %{ $hash_ref } ) ){
$k = lc $k;
$v = lc $v;
if ( exists $self->{$k} && ! ($k =~ m/^\_/) ){ #is a valid config setting and is NOT a private method
my $method = "set_".$k;
$self->$method($v); #call appropriate setter method
}else{
warn("$0:WARNING: skipping unsupported configuration setting $k => $v in hash_ref $hash_ref\n");
}
}
}else{
die("$0:ERROR: argument passed to method 'new' must be reference to a hash.\n");
}
}
return $self;
}
sub set_mhandle {
my $self = shift;
if (@_){
my $handle = shift;
$self->{mhandle} = $handle;
}
return $self->{mhandle};
}
####
$VAR1 = {
'mhandle' => \*{'::$pfh'},
'waitforchilds' => '180',
'maxchilds' => '20'
};
####
$VAR1 = bless( {
'mhandle' => 'glob(0x2161670)',
'waitforchilds' => 180,
'_handle' => undef,
'maxchilds' => 20,
'_childs' => {}
}, 'fmanager' );
####
$VAR1 = bless( {
'mhandle' => \*{'::$pfh'},
'waitforchilds' => 180,
'_handle' => undef,
'maxchilds' => 20,
'_childs' => {}
}, 'fmanager' );