Class/Collection.pm

filter: Statementstmt 82.7% 48 / 58 Branchbran 68.7% 11 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.2% 13 / 16 Podpod 100% 12 / 12 totaltotal 79.4% 85 / 107 CC 12 SCAR 12.3
CC
12
Cov
78%
find
12.0
remove
6.0
each
3.1
CRAP 3.4
« Class/Errors.pm ↑ Summary Class/Fields.pm »
1 # ABSTRACT: Generic Container Class for Various Collections
2  
3 package Validation::Class::Collection;
4 {
5 56 $Validation::Class::Collection::VERSION = '7.10_01';
6 }
7  
8 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 56 our $VERSION = '7.10_01'; # VERSION
12  
13 56 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16  
17 sub new {
18
19 186 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
20
21 186 ▶ my %arguments = @_ % 2 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 93 93 186
22
23 186 my $self = bless {}, $class;
24
25 186 ▶ while (my($name, $value) = each(%arguments)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = CORE::each %arguments) 106 186 292
26
27 106 $self->add($name => $value);
28
29 }
30
31 186 return $self;
32
33 }
34  
35  
36 sub add {
37
38 193 ▶ my $self = shift;
Subroutine add: called CC=3 SCAR=11.0
Pod documented
39
40 193 ▶ my %arguments = @_ % 2 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 193 0 193
41
42 193 ▶ while (my($key, $object) = each %arguments) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = CORE::each %arguments) 461 193 654
43
44 461 $self->{$key} = $object;
45
46 }
47
48 193 return $self;
49
50 }
51  
52  
53 sub clear {
54
55 193 ▶ my ($self) = @_;
Subroutine clear: called CC=2 SCAR=6.9
Pod documented
56
57 193 delete $self->{$_} for keys %{$self} ;
58
59 193 return $self;
60
61 }
62  
63  
64 sub count {
65
66 132 ▶ return scalar(keys %{$_[0]});
Subroutine count: called CC=1 SCAR=0.0
Pod documented
67
68 }
69  
70  
71 sub each {
72
73 1744 ▶ my ($self, $transformer) = @_;
Subroutine each: called CC=3 SCAR=11.3
Pod documented
74
75 1744 ▶ $transformer ||= sub {@_};
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$transformer ||= sub { @_; }
l!l&&r!l&&!r
174400
MC/DC0%0/2
$transformer ||= sub { @_; }
$transformer sub { @_; }
Truth table33%1/3
A ||= B
A= $transformerB= sub { @_; }
ABresult
1X1
011
000
76
77 1744 my %hash = %{$self};
78
79 1744 ▶ while (my @kv = each(%hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@kv) = CORE::each %hash) 3477 1744 5221
80
81 3477 $transformer->(@kv);
82
83 }
84
85 1744 return $self;
86
87 }
88  
89  
90 sub find {
91
92 0 ▶ my ($self, $pattern) = @_;
Subroutine find: not called CC=3 SCAR=24.8
Pod documented
93
94 0 ▶ return undef unless "REGEXP" eq uc ref $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless "REGEXP" eq uc ref $pattern 0 0 0
95
96 0 my %matches = ();
97
98 $matches{$_} = $self->{$_}
99 0 for grep { $_ =~ $pattern } keys %{$self};
100
101 0 return { %matches };
102
103 }
104  
105  
106 sub has {
107
108 942 ▶ my ($self, $name) = @_;
Subroutine has: called CC=2 SCAR=6.9
Pod documented
109
110 942 ▶ return defined $self->{$name} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$name} ? : 676 266 942
111
112 }
113  
114  
115 sub hash {
116
117 311 ▶ return {%{$_[0]}};
Subroutine hash: called CC=1 SCAR=0.0
Pod documented
118
119 }
120  
121  
122 sub keys {
123
124 486 ▶ return (keys %{$_[0]});
Subroutine keys: called CC=1 SCAR=0.0
Pod documented
125
126 }
127  
128  
129 sub list {
130
131 469 ▶ return (values %{$_[0]});
Subroutine list: called CC=1 SCAR=0.0
Pod documented
132
133 }
134  
135  
136 sub remove {
137
138 0 ▶ my ($self, $name) = @_;
Subroutine remove: not called CC=2 SCAR=17.9
Pod documented
139
140 0 ▶ return delete $self->{$name} if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
141
142 }
143  
144  
145 sub values {
146
147 469 ▶ goto &list;
Subroutine values: called CC=1 SCAR=0.0
Pod documented
148
149 }
150  
151 56 1;
152 __END__
« Class/Errors.pm ↑ Summary Class/Fields.pm »