Fix ton of buggery with defer-immutable accessor shim
[p5sagit/Class-Accessor-Grouped.git] / t / lib / AccessorGroups.pm
index 240b76d..1d70e57 100644 (file)
@@ -1,11 +1,9 @@
 package AccessorGroups;
 use strict;
 use warnings;
-use base 'Class::Accessor::Grouped';
+use base 'AccessorGroupsParent';
 
-__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', [ fieldname_torture => join ('', reverse map { chr($_) } (0..255) ) ]);
 
 sub get_simple {
   my $v = shift->SUPER::get_simple (@_);
@@ -20,14 +18,28 @@ sub set_simple {
   $_[2];
 }
 
-sub new {
-    return bless {}, shift;
-};
-
-foreach (qw/multiple listref/) {
-    no strict 'refs';
-    *{"get_$_"} = __PACKAGE__->can('get_simple');
-    *{"set_$_"} = __PACKAGE__->can('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 runtime_around { goto $around_cref };
+    sub _runtime_around_accessor { goto $around_cref };
+EOE
+}
 
 1;