Here is a bizarre and annoying error that cropped up for me in the past hour and which so far defies any logic I seem able to wrap my head around.

In this example, $self is 'My::New::Module::WWW', which absolutely has a ->_home() method, and was performing as intended until I added this new invocation to the constructor for the Admin module. Using CGI::TabPane, I have a method reading in relevant part:

sub init_admin { my $self = shift; my $id = shift || '3'; # print STDERR Dumper(\$self); # my @trace = caller; # print STDERR $trace[0] . ' ' . $trace[1] . ' ' . $trace[2]; my $admin = My::New::Module::Admin->new({ object => $self }); my($pane_1_tab_0_0) = $self->_home($id); my($pane_1_tab_0_1) = $self->_this_form(); my($pane_1_tab_0_1) = $self->_that_form(); . . . return [$pane]; }
And now I'm getting an error reading:

test-cgi-tabpane.cgi: Can't locate object method "_home" via package " +My::New::Module::Admin" at (the line reading: my($pane_1_tab_0_0) += $self->_home($id);).
But that very clearly is a call to $self->_home(), not to $admin->_home(). Both ::WWW and ::Admin include the line: use base 'My::New::Module'. My hope was that all of their various methods might be invoked as methods of the base class.

OK, I finally moved the constructor to the base package and renamed the constructors in the ::WWW and ::Admin modules and I'm still getting exactly the same error.

Now I'm really baffled and beffudled. Anyone out there who can help me unwrap this, please?

-- Hugh

UPDATE:

Thanks Chromatic! From the constructor, I now return $self as soon as I set it to $self->{'object'} which resolves the issue you identified, I think. And instead of creating an object to access the Admin->methods(), for the moment I'm content to give a fully qualified package name to those calls, so I can simply move on with this project. There are so many more pressing issues much closer to the critical path for delivery and deployment on this project, that I thought it best not to be distracted by this one too much longer.

CountZero: You are probably correct, that learning Moose (which has been on my list for a while) would be a worthwhile investment. At the moment I feel sufficiently invested in the project I'm currently working on that I don't want to get distracted by such a project at the moment. Perhaps that means re-inventing a few wheels along the way. But the path seems less of an uphill climb for the moment at any rate.

For the moment I need to stop adding new features and focus on deploying what I've already got. I have a few regression issues to deal with first. Hopefully by the end of the day. We shall see.

if( $lal && $lol ) { $life++; }

In reply to Confused by use base, I think. by hesco

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.