Fix ton of buggery with defer-immutable accessor shim
[p5sagit/Class-Accessor-Grouped.git] / t / lib / AccessorGroups.pm
1 package AccessorGroups;
2 use strict;
3 use warnings;
4 use base 'AccessorGroupsParent';
5
6 __PACKAGE__->mk_group_accessors('simple', [ fieldname_torture => join ('', reverse map { chr($_) } (0..255) ) ]);
7
8 sub get_simple {
9   my $v = shift->SUPER::get_simple (@_);
10   $v =~ s/ Extra tackled on$// if $v;
11   $v;
12 }
13
14 sub set_simple {
15   my ($self, $f, $v) = @_;
16   $v .= ' Extra tackled on' if $f eq 'singlefield';
17   $self->SUPER::set_simple ($f, $v);
18   $_[2];
19 }
20
21 # a runtime Class::Method::Modifiers style around
22 # the eval/our combo is so that we do not need to rely on Sub::Name being available
23 my $orig_ra_cref = __PACKAGE__->can('runtime_around');
24 our $around_cref = sub {
25   my $self = shift;
26   if (@_) {
27     my $val = shift;
28     $self->$orig_ra_cref($val . ' Extra tackled on');
29     $val;
30   }
31   else {
32     my $val = $self->$orig_ra_cref;
33     $val =~ s/ Extra tackled on$// if defined $val;
34     $val;
35   }
36 };
37 {
38   no warnings qw/redefine/;
39   eval <<'EOE';
40     sub runtime_around { goto $around_cref };
41     sub _runtime_around_accessor { goto $around_cref };
42 EOE
43 }
44
45 1;