blib/lib/DBI/Util/_accessor.pm

filter: Statementstmt 55.5% 40 / 72 Branchbran 25.0% 7 / 28 Conditioncond 23.0% 6 / 26 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 61.1% 11 / 18 Podpod 0.0% 0 / 10 totaltotal 38.2% 65 / 170 CC 27 SCAR 20.7
CC
27
Cov
42%
new
12.7
new
12.7
__ANON__
10.8
CRAP 7.9
« blib/lib/DBD/Gofer/Transport/Base.pm ↑ Summary blib/lib/DBD/Sponge.pm »
1 package DBI::Util::_accessor;
2 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 63 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 63 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 our $VERSION = "0.009479";
6  
7 # inspired by Class::Accessor::Fast
8  
9 7367 ▶sub new {
Subroutine new: called CC=5 SCAR=25.4
Pod undocumented
10 0 ▶ my($proto, $fields) = @_;
Subroutine new: not called CC=5 SCAR=25.4
Pod undocumented
11 0 ▶ my($class) = ref $proto || $proto;
Condition16%1/6
ref $proto || $proto
l!l&&r!l&&!r
000
ref $proto || $proto
l!l&&r!l&&!r
073670
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
12 0 ▶ $fields ||= {};
Condition25%1/4
$fields ||= {}
l!l
00
$fields ||= {}
l!l
73670
MC/DC0%0/1
$fields ||= {}
$fields
MC/DC0%0/1
$fields ||= {}
$fields
Truth table0%0/2
A
A= $fields
Aresult
11
00
Truth table50%1/2
A
A= $fields
Aresult
11
00
13  
14 0 ▶ my @dubious = grep { !m/^_/ && !$proto->can($_) } keys %$fields;
Condition16%1/6
/^_/ || $proto->can($_)
l!l&&r!l&&!r
000
/^_/ || $proto->can($_)
l!l&&r!l&&!r
0410920
MC/DC0%0/2
/^_/ || $proto->can($_)
/^_/ $proto->can($_)
MC/DC0%0/2
/^_/ || $proto->can($_)
/^_/ $proto->can($_)
Truth table0%0/3
A || B
A= /^_/B= $proto->can($_)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= /^_/B= $proto->can($_)
ABresult
1X1
011
000
15 0 ▶ carp "$class doesn't have accessors for fields: @dubious" if @dubious;
Branch: 2 branches
BranchTrueFalseTotal
if @dubious 0 0 0
if @dubious 0 7367 7367
16  
17 # make a (shallow) copy of $fields.
18 0 bless {%$fields}, $class;
19 }
20  
21 394 ▶sub mk_accessors {
Subroutine mk_accessors: called CC=1 SCAR=1.2
Pod undocumented
22 0 ▶ my($self, @fields) = @_;
Subroutine mk_accessors: not called CC=1 SCAR=1.2
Pod undocumented
23 0 $self->mk_accessors_using('make_accessor', @fields);
24 }
25  
26 583 ▶sub mk_accessors_using {
Subroutine mk_accessors_using: called CC=5 SCAR=22.7
Pod undocumented
27 0 ▶ my($self, $maker, @fields) = @_;
Subroutine mk_accessors_using: not called CC=5 SCAR=22.7
Pod undocumented
28 0 ▶ my $class = ref $self || $self;
Condition16%1/6
ref $self || $self
l!l&&r!l&&!r
000
ref $self || $self
l!l&&r!l&&!r
05830
MC/DC0%0/2
ref $self || $self
ref $self $self
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
29  
30 # So we don't have to do lots of lookups inside the loop.
31 0 ▶ $maker = $self->can($maker) unless ref $maker;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $maker 0 0 0
unless ref $maker 583 0 583
32  
33 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 0 foreach my $field (@fields) {
35 0 my $accessor = $self->$maker($field);
36 0 *{$class."\:\:$field"} = $accessor
37 0 ▶ unless defined &{$class."\:\:$field"};
Branch: 2 branches
BranchTrueFalseTotal
unless defined &{$class . "::$field";} 0 0 0
unless defined &{$class . "::$field";} 3237 0 3237
38 }
39 #my $hash_ref = \%{$class."\:\:_accessors_hash};
40 #$hash_ref->{$_}++ for @fields;
41 # XXX also copy down _accessors_hash of base class(es)
42 # so one in this class is complete
43 0 return;
44 }
45  
46 3048 ▶sub make_accessor {
Subroutine make_accessor: called CC=1 SCAR=1.5
Pod undocumented
47 0 ▶ my($class, $field) = @_;
Subroutine make_accessor: not called CC=1 SCAR=1.5
Pod undocumented
48 266121 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=15.3
49 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=15.3
50 0 ▶ return $self->{$field} unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 0 0 0
unless @_ 224008 42113 266121
51 0 ▶ croak "Too many arguments to $field" if @_ > 1;
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 0 0
if @_ > 1 0 42113 42113
52 0 return $self->{$field} = shift;
53 0 };
54 }
55  
56 189 ▶sub make_accessor_autoviv_hashref {
Subroutine make_accessor_autoviv_hashref: called CC=1 SCAR=3.0
Pod undocumented
57 0 ▶ my($class, $field) = @_;
Subroutine make_accessor_autoviv_hashref: not called CC=1 SCAR=3.0
Pod undocumented
58 200 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=23.7
59 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=4 SCAR=23.7
60 0 ▶ return $self->{$field} ||= {} unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 0 0 0
unless @_ 200 0 200
Condition50%2/4
$self->{$field} ||= {}
l!l
00
$self->{$field} ||= {}
l!l
12080
MC/DC0%0/1
$self->{$field} ||= {}
$self->{$field}
MC/DC100%1/1
$self->{$field} ||= {}
$self->{$field}
Truth table0%0/2
A
A= $self->{$field}
Aresult
11
00
Truth table100%2/2
A
A= $self->{$field}
Aresult
11
00
61 0 ▶ croak "Too many arguments to $field" if @_ > 1;
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 0 0
if @_ > 1 0 0 0
62 0 return $self->{$field} = shift;
63 0 };
64 }
65  
66 1;
« blib/lib/DBD/Gofer/Transport/Base.pm ↑ Summary blib/lib/DBD/Sponge.pm »