tj_thompson has asked for the wisdom of the Perl Monks concerning the following question:
I have an issue I'm debugging that is making me question my somewhat limited understanding of method resolution. The below Pl and Pattern classes are Moose classes utilizing MooseX::Types and MooseX::Params::Validate.
First, here's the line where things go haywire in the debugger (apologies for width):
DB<18> . Program::Plist::Pl::_create_pattern_obj(/nfs/pdx/disks/nehalem.pde.077 +/projects/lib/Program-Plist-Pl/lib/Program/Plist/Pl.pm:62): 62: my $pattern_obj = Program::Plist::Pl::Pattern->new(name => + $name, 63: mask_da +ta => $mask_data, 64: tags => + $tags);
This call should first check the Program::Plist::Pl::Pattern symbol table for a new entry. Here's our symbol table:
DB<3> print Dumper(\%Program::Plist::Pl::Pattern::); $VAR1 = { 'import' => *Program::Plist::Pl::Pattern::import, 'meta' => *Program::Plist::Pl::Pattern::meta, 'ISA' => *Program::Plist::Pl::Pattern::ISA, 'BEGIN' => *Program::Plist::Pl::Pattern::BEGIN, 'isa' => *Program::Plist::Pl::Pattern::isa };
Ok, no new entry here. Next step should be checking Pattern's @ISA for parents:
DB<4> print Dumper \@Program::Plist::Pl::Pattern::ISA $VAR1 = [ 'Moose::Object' ];
We have Moose::Object as a parent. Next step should be checking to see if this parent class has a 'new' entry in its symbol table (some entries deleted for readability):
DB<6> print Dumper \%Moose::Object:: $VAR1 = { '__mx_is_compiled' => *Moose::Object::__mx_is_compiled, 'new' => *Moose::Object::new, 'DOES' => *Moose::Object::DOES };
Ok, it appears that we have a new entry for Moose::Object. At this point, I would assume that &Moose::Object::new(@args) would be called. I have a locally modified version of that library that prints args when called. Let's make certain it works:
DB<14> &Moose::Object::new('arg1'); MOOSE->NEW CALLED WITH ARGS (arg1) Can't locate object method "BUILDARGS" via package "arg1" (perhaps you + forgot to load "arg1"?) at /nfs/pdx/disks/nehalem.pde.077/debug/Moos +e/Object.pm line 25, <$fh> line 8.
Ok, verified that my code does print when the Moose::Object::new method is called. Let's execute our problem line and see what happens. First, our line is:
DB<1> c Program::Plist::Pl::_create_pattern_obj(/nfs/pdx/disks/nehalem.pde.077 +/projects/lib/Program-Plist-Pl/lib/Program/Plist/Pl.pm:62): 62: my $pattern_obj = Program::Plist::Pl::Pattern->new(name => + $name, 63: mask_da +ta => $mask_data, 64: tags => + $tags);
And issuing a single step command to the debugger results in this:
DB<18> s MooseX::Types::EXPORTED_TYPE_CONSTRAINT=CODE(0x1ec2ca8)(/nfs/pdx/disks +/nehalem.pde.077/debug/MooseX/Types.pm:386): 386: my $type_constraint = $class->create_base_type_constra +int($name);
How did I get to MooseX::Types::EXPORTED_TYPE_CONSTRAINT? I don't see the output for Moose::Object::new at all, meaning I didn't get there. How have I short circuited the symbol table lookups to get to this code? Is my understanding of how a method is found wrong? My inability to trace this code has made debugging my issue very difficult.
It would appear this code is being called to deal with the arguments to the Pattern->new call, but I see no functions in the arguments to the call.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose, @ISA and method resolution
by stvn (Monsignor) on Jan 11, 2011 at 01:12 UTC | |
|
Re: Moose, @ISA and method resolution
by tj_thompson (Monk) on Jan 11, 2011 at 05:19 UTC | |
by stvn (Monsignor) on Jan 13, 2011 at 02:36 UTC | |
by tilly (Archbishop) on Jan 13, 2011 at 15:38 UTC | |
by stvn (Monsignor) on Jan 14, 2011 at 04:09 UTC |