Hi All. I'm busy converting my CMS over to OO, exactly why I'm not sure but I'm sure the grass is greener on the other side. I have hit my first issue, and having read the guides I'm unsure on how to resolve it.

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)


In reply to OO Conversion Query - Sharing Data by snoopy20

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.