snoopy20 has asked for the wisdom of the Perl Monks concerning the following question:
I have a module 'igaro.pm', which loads critical modules in the 'core' folder. These modules are instantiated into the parents $self hash. However many modules will need access to the parents hash, in order to get at a piece of data.
The only way I can see on how to fix it would be to pass the required hash values with the call to the child, but this seems messy. Here's my code so far…
package igaro; use 5.6.0; use strict; use warnings; our $VERSION = '1.00'; sub new { my $class = shift; my %params = @_; my $self = bless { uri => undef, dbh => undef, form => undef, cookies => undef, data => {}, action => $params{settings}{defaultfunction}, settings => delete $params{settings}, language => undef, date => undef, cache => {} } => $class; $self->{data}{template}='main'; return $self; } sub exec { my $self = shift; $self->{data} = {}; use igaro::core::dbh::connection; $self->{dbh} = igaro::core::dbh::connection->new(type=>$self->{set +tings}{database}{type}, name=>$self->{settings}{database}{name}, pass +word=>$self->{settings}{database}{password}, username=>$self->{settin +gs}{database}{username}, connect=>$self->{settings}{database}{connect +} ) if undefined $self->{dbh}; use igaro::core::language::cache; $self->{language} = igaro::core::language::cache->new if undefined + $self->{language}; use igaro::core::date::now; $self->{date} = igaro::core::date::now->new(); use igaro::core::uri::env; $self->{uri} = igaro::core::uri::env->new(); $self->{action} = $self->{uri}->{i} if $self->{uri}->{i}; use igaro::core::form::env; $self->{form} = igaro::core::form::env->new(); use igaro::core::cookies::env; $self->{cookies} = igaro::core::cookies::env->new(); use igaro::core::usergroups::cache; $self->{cache}{usergroups} = igaro::core::usergroups::cache->new(d +bh=>$self->{dbh}->get) if undefined $self->{cache}{usergroups}; use igaro::core::session::load; $self->{session} => igaro::core::session::load->new(cookie=>$self- +>{cookies}->get('session'), dbh=>$self->{dbh}->get); } 1;
Example; on igaro::core::session::load, I passed the cookie and the dbh handle. Can the child not get it itself?
Or do I pass a copy of the parent, like:
$self->{session} => igaro::core::session::load->new(parent=>$self)
|
|---|