danb has asked for the wisdom of the Perl Monks concerning the following question:
(A related, unanswered question: http://www.perlmonks.org/index.pl?node_id=234516).
I'm trying to utilize Class::MethodMaker for my open source shipping module (http://www.kavod.com/Business-Shipping), but currently, none of the MethodMaker-generated methods call SUPER. So, extended MethodMaker with a subclass that does, but that results in this error:
Can't locate auto/CustomMethodMaker/SUPER/required.al in @INC
(Where $method_name happened to be "required" at the time). My pet theory is that SUPER only works within the context of the correct package, and MethodMaker isn't it. I've tried to reduce all of the code down to the simplest example possible that still exhibits the problem, and pasted it below.
My questions are:
I would greatly appreciate any comments. Cheers,
-- Dan Browning, Kavod Technologies, <db@kavod.com> 360.843.4074x217 6700 NE 162nd Ave, Ste 611-210, Vancouver, WA. Random Fortune: Consultant, n.: An ordinary man a long way from home.
###################################################################### ## CustomMethodMaker ## (must be in it's own file, due to the fact that ## it has to be 'used'. ###################################################################### package CustomMethodMaker; use base ( 'Class::MethodMaker' ); =head2 grouped_fields_inherit Works like grouped_fields, except that it also calls the parent class. =cut sub grouped_fields_inherit { my ($class, %args) = @_; my %methods; foreach (keys %args) { my @slots = @{$args{$_}}; $class->get_set(@slots); my $method_name = $_; $methods{$_} = sub { my ( $self ) = @_; my @parent_slots = (); my $to_execute = "SUPER::$method_name"; # # The following line causes this error: # #Can't locate auto/CustomMethodMaker/SUPER/<METHOD>.al in @INC # @parent_slots = $self->$to_execute(); return ( @parent_slots, @slots ); }; } $class->install_methods(%methods); } 1; #!/usr/bin/perl use strict; use warnings; # See CustomMethodMaker.pm ###################################################################### ## Bug ###################################################################### package Bug; use Class::MethodMaker new_hash_init => 'new', grouped_fields => [ 'required' => [ 'id', 'type', 'description' ], 'optional' => [ 'severity' ], ]; ###################################################################### ## FixedBug ###################################################################### package FixedBug; use base ( 'Bug' ); use CustomMethodMaker new_hash_init => 'new', grouped_fields_inherit => [ 'required' => [ 'date_fixed', 'repairer' ], 'optional' => [ 'repair_notes', 'patch_file' ], ]; ###################################################################### ## Main ###################################################################### package Main; my $bug = Bug->new(); print join( ', ', $bug->required() ) . "\n"; # # Prints 'id', 'type', 'description' # my $fixed_bug = FixedBug->new(); print join( ', ', $fixed_bug->required() ) . "\n"; # # Prints 'date_fixed', 'repairer' -- but I want it to print: # 'id', 'type', 'description', 'date_fixed', 'repairer' #
|
|---|