hesco has asked for the wisdom of the Perl Monks concerning the following question:
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:
And now I'm getting an error reading: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]; }
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.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);).
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confused by use base, I think.
by chromatic (Archbishop) on Jun 15, 2008 at 06:27 UTC | |
|
Re: Confused by use base, I think.
by hesco (Deacon) on Jun 15, 2008 at 07:52 UTC | |
by chromatic (Archbishop) on Jun 15, 2008 at 13:21 UTC | |
|
Re: Confused by use base, I think.
by ikegami (Patriarch) on Jun 15, 2008 at 05:54 UTC | |
|
Re: Confused by use base, I think.
by CountZero (Bishop) on Jun 15, 2008 at 20:04 UTC | |
|
Re: Confused by use base, I think.
by Herkum (Parson) on Jun 15, 2008 at 03:33 UTC | |
by ikegami (Patriarch) on Jun 15, 2008 at 05:56 UTC | |
by Herkum (Parson) on Jun 15, 2008 at 15:03 UTC | |
by ikegami (Patriarch) on Jun 15, 2008 at 15:26 UTC | |
by Herkum (Parson) on Jun 15, 2008 at 19:23 UTC |