X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FAccessorGroups.pm;h=a8e3b971deb8f3710e353ba19a1f16d217584d53;hb=ba8c183b7c3d71a5b8fcd936916e80a7b87f7961;hp=b7188e9e26f316cff4a54b10bb9e1a651edd9b16;hpb=85ccab9a83c665219c454f68486301ca51e02b2c;p=p5sagit%2FClass-Accessor-Grouped.git diff --git a/t/lib/AccessorGroups.pm b/t/lib/AccessorGroups.pm index b7188e9..a8e3b97 100644 --- a/t/lib/AccessorGroups.pm +++ b/t/lib/AccessorGroups.pm @@ -17,6 +17,7 @@ use base 'Class::Accessor::Grouped'; __PACKAGE__->mk_group_accessors('simple', 'singlefield'); __PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/); __PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]); +__PACKAGE__->mk_group_accessors('simple', 'runtime_around'); sub get_simple { my $v = shift->SUPER::get_simple (@_); @@ -31,14 +32,38 @@ sub set_simple { $_[2]; } +# a runtime Class::Method::Modifiers style around +# the eval/our combo is so that we do not need to rely on Sub::Name being available +my $orig_ra_cref = __PACKAGE__->can('runtime_around'); +our $around_cref = sub { + my $self = shift; + if (@_) { + my $val = shift; + $self->$orig_ra_cref($val . ' Extra tackled on'); + $val; + } + else { + my $val = $self->$orig_ra_cref; + $val =~ s/ Extra tackled on$// if defined $val; + $val; + } +}; +{ + no warnings qw/redefine/; + eval <<'EOE'; + sub AccessorGroups::runtime_around { goto $AccessorGroups::around_cref }; + sub AccessorGroups::_runtime_around_accessor { goto $AccessorGroups::around_cref }; +EOE +} + sub new { - return bless {}, shift; + return bless {}, shift; }; foreach (qw/multiple listref/) { - no strict 'refs'; - *{"get_$_"} = __PACKAGE__->can('get_simple'); - *{"set_$_"} = __PACKAGE__->can('set_simple'); + no strict 'refs'; + *{"get_$_"} = __PACKAGE__->can('get_simple'); + *{"set_$_"} = __PACKAGE__->can('set_simple'); }; 1;