| 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
ref $proto || $proto
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
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | $fields ||= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$fields ||= {}
$fields ||= {}
MC/DC0%0/1
$fields ||= {}
$fields
MC/DC0%0/1
$fields ||= {}
$fields
Truth table0%0/2
A
A= $fields
Truth table50%1/2
A
A= $fields
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my @dubious = grep { !m/^_/ && !$proto->can($_) } keys %$fields; | ||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
/^_/ || $proto->can($_)
/^_/ || $proto->can($_)
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($_)
Truth table33%1/3
A || B
A= /^_/B= $proto->can($_)
| |||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | carp "$class doesn't have accessors for fields: @dubious" if @dubious; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 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
ref $self || $self
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
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | croak "Too many arguments to $field" if @_ > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition50%2/4
$self->{$field} ||= {}
$self->{$field} ||= {}
MC/DC0%0/1
$self->{$field} ||= {}
$self->{$field}
MC/DC100%1/1
$self->{$field} ||= {}
$self->{$field}
Truth table0%0/2
A
A= $self->{$field}
Truth table100%2/2
A
A= $self->{$field}
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak "Too many arguments to $field" if @_ > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $self->{$field} = shift; | |||||||||||||||||||||||||||||||||||||
| 63 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 1; | ||||||||||||||||||||||||||||||||||||||