X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FAccessorGroups.pm;h=10801c8a84ba21afea6d0ac666623e468832550c;hb=4d70ba11c00e532cd69f2f044f8e27abae0ccd0b;hp=97bf7f10ff8cf60f8ca6fa4cbf0c4a4baee69c17;hpb=e7d391a81cfb99725a120fb58b80534f73962c6d;p=p5sagit%2FClass-Accessor-Grouped.git diff --git a/t/lib/AccessorGroups.pm b/t/lib/AccessorGroups.pm index 97bf7f1..10801c8 100644 --- a/t/lib/AccessorGroups.pm +++ b/t/lib/AccessorGroups.pm @@ -1,24 +1,70 @@ +{ + package AccessorGroups::BeenThereDoneThat; + + use strict; + use warnings; + use base 'Class::Accessor::Grouped'; + + __PACKAGE__->mk_group_accessors('simple', 'singlefield'); + __PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/); +} + + package AccessorGroups; use strict; use warnings; use base 'Class::Accessor::Grouped'; - -__PACKAGE__->mk_group_accessors('single', 'singlefield'); +__PACKAGE__->mk_group_accessors('simple', 'singlefield'); __PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/); -__PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1field/], [qw/lr2name lr2field/]); +__PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]); +__PACKAGE__->mk_group_accessors('simple', 'runtime_around'); +__PACKAGE__->mk_group_accessors('simple', [ fieldname_torture => join ('', map { chr($_) } (0..255) ) ]); -sub new { - return bless {}, shift; -}; +sub get_simple { + my $v = shift->SUPER::get_simple (@_); + $v =~ s/ Extra tackled on$// if $v; + $v; +} -foreach (qw/single multiple listref/) { - no strict 'refs'; +sub set_simple { + my ($self, $f, $v) = @_; + $v .= ' Extra tackled on' if $f eq 'singlefield'; + $self->SUPER::set_simple ($f, $v); + $_[2]; +} - *{"get_$_"} = \&Class::Accessor::Grouped::get_simple; - *{"set_$_"} = \&Class::Accessor::Grouped::set_simple; +# 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 +} -# make cleanup DESTROY happy -sub get_warnings {}; +sub new { + return bless {}, shift; +}; + +foreach (qw/multiple listref/) { + no strict 'refs'; + *{"get_$_"} = __PACKAGE__->can('get_simple'); + *{"set_$_"} = __PACKAGE__->can('set_simple'); +}; 1;