Accessor/Faster.pm

filter: Statementstmt 82.8% 53 / 64 Branchbran 57.5% 23 / 40 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 15 / 18 Podpod 100% 4 / 4 totaltotal 73.2% 96 / 131 CC 23 SCAR 11.6
CC
23
Cov
72%
new
4.1
__ANON__
4.0
__ANON__
4.0
CRAP 3.2
« Accessor.pm ↑ Summary Accessor/Fast.pm »
1 package Class::Accessor::Faster;
2 3 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use B 'perlstring';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 $Class::Accessor::Faster::VERSION = '0.51';
6  
7 3 my %slot;
8 26 ▶sub _slot {
Subroutine _slot: called CC=2 SCAR=6.9
9 26 my($class, $field) = @_;
10 26 my $n = $slot{$class}->{$field};
11 26 ▶ return $n if defined $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 10 16 26
12 16 $n = keys %{$slot{$class}};
13 16 $slot{$class}->{$field} = $n;
14 16 return $n;
15 }
16  
17 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
18 4 my($proto, $fields) = @_;
19 4 ▶ my($class) = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
20 4 my $self = bless [], $class;
21  
22 4 ▶ $fields = {} unless defined $fields;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields 1 3 4
23 4 for my $k (keys %$fields) {
24 8 my $n = $class->_slot($k);
25 8 $self->[$n] = $fields->{$k};
26 }
27 4 return $self;
28 }
29  
30 6 ▶sub make_accessor {
Subroutine make_accessor: called CC=1 SCAR=0.9
Pod documented
31 6 my($class, $field) = @_;
32 6 my $n = $class->_slot($field);
33 0 ▶ eval sprintf q{
Subroutine __ANON__: called CC=3 SCAR=14.0
Subroutine __ANON__: called CC=3 SCAR=14.0
Subroutine __ANON__: not called CC=3 SCAR=14.0
Subroutine __ANON__: called CC=3 SCAR=14.0
Subroutine __ANON__: not called CC=3 SCAR=14.0
Subroutine __ANON__: called CC=3 SCAR=14.0
Branch: 12 branches
BranchTrueFalseTotal
if scalar @_ == 1 4 2 6
scalar @_ == 2 ? : 1 1 2
if scalar @_ == 1 1 1 2
scalar @_ == 2 ? : 1 0 1
if scalar @_ == 1 0 0 0
scalar @_ == 2 ? : 0 0 0
if scalar @_ == 1 1 1 2
scalar @_ == 2 ? : 1 0 1
if scalar @_ == 1 0 0 0
scalar @_ == 2 ? : 0 0 0
if scalar @_ == 1 2 0 2
scalar @_ == 2 ? : 0 0 0
34 sub {
35 return $_[0][%d] if scalar(@_) == 1;
36 return $_[0][%d] = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]];
37 }
38 }, $n, $n;
39 }
40  
41 6 ▶sub make_ro_accessor {
Subroutine make_ro_accessor: called CC=1 SCAR=0.6
Pod documented
42 6 my($class, $field) = @_;
43 6 my $n = $class->_slot($field);
44 0 ▶ eval sprintf q{
Subroutine __ANON__: called CC=2 SCAR=8.7
Subroutine __ANON__: not called CC=2 SCAR=8.7
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 5 1 6
if @_ == 1 0 0 0
45 sub {
46 return $_[0][%d] if @_ == 1;
47 my $caller = caller;
48 $_[0]->_croak(sprintf "'$caller' cannot alter the value of '%%s' on objects of class '%%s'", %s, %s);
49 }
50 }, $n, map(perlstring($_), $field, $class);
51 }
52  
53 6 ▶sub make_wo_accessor {
Subroutine make_wo_accessor: called CC=1 SCAR=0.1
Pod documented
54 6 my($class, $field) = @_;
55 6 my $n = $class->_slot($field);
56 0 ▶ eval sprintf q{
Subroutine __ANON__: called CC=3 SCAR=11.5
Subroutine __ANON__: called CC=3 SCAR=11.5
Branch: 4 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 3 3
if @_ == 2 2 1 3
if (@_ == 1) { } 1 1 2
if @_ == 2 1 0 1
57 sub {
58 if (@_ == 1) {
59 my $caller = caller;
60 $_[0]->_croak(sprintf "'$caller' cannot access the value of '%%s' on objects of class '%%s'", %s, %s);
61 }
62 else {
63 return $_[0][%d] = $_[1] if @_ == 2;
64 return (shift)->[%d] = \@_;
65 }
66 }
67 }, map(perlstring($_), $field, $class), $n, $n;
68 }
69  
70 3 1;
71  
72 __END__
« Accessor.pm ↑ Summary Accessor/Fast.pm »