File: AccessorGroups.pm

package info (click to toggle)
libclass-accessor-grouped-perl 0.10012-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 356 kB
  • ctags: 187
  • sloc: perl: 2,553; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package AccessorGroups;
use strict;
use warnings;
use base 'AccessorGroupsParent';

__PACKAGE__->mk_group_accessors('simple', [ fieldname_torture => join ('', reverse map { chr($_) } (0..255) ) ]);

sub get_simple {
  my $v = shift->SUPER::get_simple (@_);
  $v =~ s/ Extra tackled on$// if $v;
  $v;
}

sub set_simple {
  my ($self, $f, $v) = @_;
  $v .= ' Extra tackled on' if $f eq 'singlefield';
  $self->SUPER::set_simple ($f, $v);
  $_[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 runtime_around { goto $around_cref };
    sub _runtime_around_accessor { goto $around_cref };
EOE
}

1;