###################################################################### ## 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/.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' #