Switch to 2-space indent, minor formatting (no code) changes
[p5sagit/Class-Accessor-Grouped.git] / t / lib / AccessorGroups.pm
CommitLineData
85ccab9a 1{
2 package AccessorGroups::BeenThereDoneThat;
3
4 use strict;
5 use warnings;
6 use base 'Class::Accessor::Grouped';
7
8 __PACKAGE__->mk_group_accessors('simple', 'singlefield');
9 __PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/);
10}
11
12
e7d391a8 13package AccessorGroups;
14use strict;
15use warnings;
16use base 'Class::Accessor::Grouped';
9540f4e4 17__PACKAGE__->mk_group_accessors('simple', 'singlefield');
28344104 18__PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/);
19__PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]);
de167379 20__PACKAGE__->mk_group_accessors('simple', 'runtime_around');
e7d391a8 21
fee7c68b 22sub get_simple {
23 my $v = shift->SUPER::get_simple (@_);
24 $v =~ s/ Extra tackled on$// if $v;
25 $v;
26}
27
28sub set_simple {
29 my ($self, $f, $v) = @_;
30 $v .= ' Extra tackled on' if $f eq 'singlefield';
31 $self->SUPER::set_simple ($f, $v);
32 $_[2];
33}
34
de167379 35# a runtime Class::Method::Modifiers style around
36# the eval/our combo is so that we do not need to rely on Sub::Name being available
37my $orig_ra_cref = __PACKAGE__->can('runtime_around');
38our $around_cref = sub {
39 my $self = shift;
40 if (@_) {
41 my $val = shift;
42 $self->$orig_ra_cref($val . ' Extra tackled on');
43 $val;
44 }
45 else {
46 my $val = $self->$orig_ra_cref;
47 $val =~ s/ Extra tackled on$// if defined $val;
48 $val;
49 }
50};
51{
52 no warnings qw/redefine/;
53 eval <<'EOE';
54 sub AccessorGroups::runtime_around { goto $AccessorGroups::around_cref };
55 sub AccessorGroups::_runtime_around_accessor { goto $AccessorGroups::around_cref };
56EOE
57}
58
e7d391a8 59sub new {
ba8c183b 60 return bless {}, shift;
e7d391a8 61};
62
28344104 63foreach (qw/multiple listref/) {
ba8c183b 64 no strict 'refs';
65 *{"get_$_"} = __PACKAGE__->can('get_simple');
66 *{"set_$_"} = __PACKAGE__->can('set_simple');
28344104 67};
68
e7d391a8 691;