Class/Accessor/Array.pm

filter: Statementstmt 76.3% 42 / 55 Branchbran 31.2% 5 / 16 Conditioncond 50.0% 2 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 2 / 2 totaltotal 68.1% 62 / 91 CC 13 SCAR 25.4
CC
13
Cov
65%
__ANON__
42.0
__ANON__
6.0
__ANON__
5.0
CRAP 12.7
« Class/Accessor/Hash.pm ↑ Summary Error.pm »
1 package EntityModel::Class::Accessor::Array;
2 3 $EntityModel::Class::Accessor::Array::VERSION = '0.016';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw{EntityModel::Class::Accessor};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use EntityModel::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use EntityModel::Log ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Class::ISA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 my %watcher;
13  
14 =head1 NAME
15  
16 EntityModel::Class::Accessor::Array - generic class accessor for arrays
17  
18 =head1 VERSION
19  
20 Version 0.016
21  
22 =head1 DESCRIPTION
23  
24 See L<EntityModel::Class>.
25  
26 =head1 METHODS
27  
28 =cut
29  
30 =head2 method_list
31  
32 Returns the method definition to add to the class.
33  
34 =cut
35  
36 1 ▶sub method_list {
Subroutine method_list: called CC=2 SCAR=9.5
Pod documented
37 1 my ($class, %opt) = @_;
38 1 my $k = $opt{k};
39 1 ▶ if(my $pre = $opt{pre}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $opt{'pre'}) { } 0 1 1
40 0 ▶ return sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
41 0 my $self = shift;
42 0 ▶ die "Options not supported for Array" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
43 0 ▶ $opt{pre}->($self, @_) or return;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"pre"}->($self, @_) or return 0 0 0
44 0 ▶ unless($self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$k}) 0 0 0
45 0 ▶ my @watchers = map { @{ $watcher{$_}->{$k} // [] } } Class::ISA::self_and_super_path(ref $self);
Condition0%0/2
$watcher{$_}{$k} // []
l!l
00
MC/DC0%0/1
$watcher{$_}{$k} // []
$watcher{$_}{$k}
Truth table0%0/2
A
A= $watcher{$_}{$k}
Aresult
11
00
46 0 logDebug("Watcher for [%s] method [%s] has %d entries", ref $self, $k, scalar @watchers);
47 $self->{$k} = EntityModel::Array->new($self->{$k},
48 (@watchers)
49 0 ▶ ? (onchange => [ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 logDebug("Check [%s] for [%s]", ref $self, $k);
51 # Pass value only
52 0 $_->($self, @_) foreach @watchers;
53 0 ▶ } ]) : ()
Branch: 1 branch
BranchTrueFalseTotal
@watchers ? : 0 0 0
54 );
55 }
56 0 return $self->{$k};
57 0 };
58 } else {
59 7 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
60 7 my $self = shift;
61 7 ▶ die "Options not supported for Array" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 7 7
62 7 ▶ unless($self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$k}) 1 6 7
63 my @watchers = map {
64 1 ▶ @{ $watcher{$_}->{$k} // [] }
Condition100%2/2
$watcher{$_}{$k} // []
l!l
11
MC/DC100%1/1
$watcher{$_}{$k} // []
$watcher{$_}{$k}
Truth table100%2/2
A
A= $watcher{$_}{$k}
Aresult
11
00
65 } Class::ISA::self_and_super_path(ref $self);
66  
67 1 logDebug("Watcher for [%s] method [%s] has %d entries", ref $self, $k, scalar @watchers);
68 $self->{$k} = EntityModel::Array->new($self->{$k},
69 (@watchers)
70 4 ▶ ? (onchange => [ $self->sap(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
71 4 my $self = shift;
72 4 logDebug("Check [%s] for [%s]", ref $self, $k);
73 # Pass value only
74 4 $_->($self, @_) foreach @watchers;
75 1 ▶ }) ]) : ()
Branch: 1 branch
BranchTrueFalseTotal
@watchers ? : 1 0 1
76 );
77 }
78 7 return $self->{$k};
79 1 };
80 }
81 }
82  
83 =head2 add_watcher
84  
85 Add this to the list of watchers for the class.
86  
87 =cut
88  
89 1 ▶sub add_watcher {
Subroutine add_watcher: called CC=1 SCAR=0.0
Pod documented
90 1 my ($class, $pkg, $meth, @sub) = @_;
91 1 logDebug("Watching [%s] for [%s]", $meth, $pkg);
92 1 push @{$watcher{$pkg}->{$meth}}, @sub;
93 1 return 1;
94 }
95  
96 3 1;
97  
98 __END__
« Class/Accessor/Hash.pm ↑ Summary Error.pm »