accessors/classic.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 96.8% 31 / 32 CC 2 SCAR 2.2
CC
2
Cov
100%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« accessors.pm ↑ Summary accessors/ro.pm »
1 =head1 NAME
2  
3 accessors::classic - create 'classic' read/write accessor methods in caller's package.
4  
5 =head1 SYNOPSIS
6  
7 package Foo;
8 use accessors::classic qw( foo bar baz );
9  
10 my $obj = bless {}, 'Foo';
11  
12 # always return the current value, even on set:
13 $obj->foo( 'hello ' ) if $obj->bar( 'world' ) eq 'world';
14  
15 print $obj->foo, $obj->bar, $obj->baz( "!\n" );
16  
17 =cut
18  
19 package accessors::classic;
20  
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use base qw( accessors );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 our $VERSION = '1.01';
26 2 our $REVISION = (split(/ /, ' $Revision: 1.5 $ '))[2];
27  
28 2 ▶use constant style => 'classic';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 5 ▶sub create_accessor {
Subroutine create_accessor: called CC=1 SCAR=0.0
Pod undocumented
31 5 my ($class, $accessor, $property) = @_;
32 # set/get is slightly faster if we eval instead of using a closure + anon
33 # sub, but the difference is marginal (~5%), and this uses less memory...
34 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶ *{$accessor} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
36 6 ▶ (@_ > 1) ? $_[0]->{$property} = $_[1] : $_[0]->{$property};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 4 2 6
37 }
38 5 }
39  
40 2 1;
41  
42 __END__
« accessors.pm ↑ Summary accessors/ro.pm »