#################################################################### ## CustomMethodMaker #################################################################### package CustomMethodMaker; use base ( 'Class::MethodMaker' ); use Carp; =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 = $_; my $caller = $class->find_target_class(); $methods{$_} = sub { my ( $self ) = @_; my @parent_slots = (); my $to_execute = "SUPER::$method_name"; # # Without $caller and eval, the following line causes this error: # # Can't locate auto/CustomMethodMaker/SUPER/[METHOD].al in @INC # @parent_slots = eval "package $caller; return \$self->SUPER::$method_name(\@_); 1" or die $@; return ( @parent_slots, @slots ); }; } $class->install_methods(%methods); } 1;