Let me make this a lot simpler: Is there a way to let multiple packages (with subs named the same) share one $self? My below example shows how I'd like to use this whole mess (see comments in the code for further details):
eval { my $foo = OurParentPackage->new; $SIG{__WARN__} = sub { die @_ }; $foo->initialize; $foo->run; }; if ($@) { print "content-type: text/html\n\n$@"; exit; } package OurParentPackage; sub new { bless { }, shift; } sub initialize { my $self = shift; require CGI; $self->{CGI} = new CGI; $self->{Config} = { 'this' => 'that' }; # config hash would be loa +ded here. # and some 'global' stuff.... $self->{script_build} = 1; $self->{script_version} = '1.0 alpha'; return $self; } sub run { my $self = shift; if ($self->{CGI}->param('area') eq 'widgetone') { if ($self->{CGI}->param('act') eq 'add') { WidgetOne->add; } else { WidgetOne->default; } } elsif ($self->{CGI}->param('area') eq 'widgettwo') { if ($self->{CGI}->param('act') eq 'add') { WidgetTwo->add; } else { WidgetTwo->default; } } elsif ($self->{CGI}->param('area') eq 'widgetthree') { # etc.... } } package WidgetOne; sub default { my $self = shift; ############ # the below line wont work because it needs the the above subs $se +lf. I need to get its $self here somehow without re-running OurParent +Package's initialize sub. print $self->{CGI}->header; ############ } sub add { my $self = shift; # code to add a 'WidgetOne' would go here. } package WidgetTwo; sub default { my $self = shift; # the default 'WidgetTwo' page code would be here... } sub add { my $self = shift; # code to add a 'WidgetTwo' would go here. } package WidgetThree; sub default { my $self = shift; # the default 'WidgetThree' page code would be here... } sub add { my $self = shift; # code to add a 'WidgetTwo' would go here. }

In reply to Re: Re: Re: Passing self from class to class? by Anonymous Monk
in thread Passing self from class to class? by Anonymous Monk

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.