Class/Errors.pm

filter: Statementstmt 72.2% 39 / 54 Branchbran 50.0% 9 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 64.2% 9 / 14 Podpod 100% 11 / 11 totaltotal 66.6% 68 / 102 CC 13 SCAR 12.5
CC
13
Cov
64%
each
6.0
find
6.0
first
6.0
CRAP 3.5
« Class/Base.pm ↑ Summary Class/Collection.pm »
1 # ABSTRACT: Error Handling Object for Fields and Classes
2  
3 package Validation::Class::Errors;
4 {
5 56 $Validation::Class::Errors::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  
14  
15 sub new {
16
17 487 ▶ my $class = shift;
Subroutine new: called CC=5 SCAR=16.3
Pod documented
18
19 487 ▶ my @arguments = @_ ? @_ > 1 ? @_ : "ARRAY" eq ref $_[0] ? @{$_[0]} : () : ();
Branch: 3 branches
BranchTrueFalseTotal
@_ ? : 224 263 487
@_ > 1 ? : 0 224 224
'ARRAY' eq ref $_[0] ? : 224 0 224
20
21 487 my $self = bless [], $class;
22
23 487 $self->add($_) for @arguments;
24
25 487 return $self;
26
27 }
28  
29  
30 sub add {
31
32 824 ▶ my ($self, @error_messages) = @_;
Subroutine add: called CC=2 SCAR=6.9
Pod documented
33
34 824 ▶ return undef unless @error_messages;
Branch: 1 branch
BranchTrueFalseTotal
unless @error_messages 635 189 824
35
36 189 my %seen = map { $_ => 1 } @{$self};
37
38 189 push @{$self}, grep { !$seen{$_} } @error_messages;
39
40 189 return $self;
41
42 }
43  
44  
45 sub all {
46
47 982 ▶ return (@{$_[0]});
Subroutine all: called CC=1 SCAR=0.0
Pod documented
48
49 }
50  
51  
52 sub clear {
53
54 1401 ▶ my ($self) = @_;
Subroutine clear: called CC=2 SCAR=6.9
Pod documented
55
56 1401 delete $self->[($_ - 1)] for (1..$self->count) ;
57
58 1401 return $self;
59
60 }
61  
62  
63 sub count {
64
65 1404 ▶ return scalar(@{$_[0]});
Subroutine count: called CC=1 SCAR=0.0
Pod documented
66
67 }
68  
69  
70 sub each {
71
72 0 ▶ my ($self, $transformer) = @_;
Subroutine each: not called CC=2 SCAR=17.9
Pod documented
73
74 0 ▶ $transformer ||= sub {@_} ;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$transformer ||= sub { @_; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$transformer ||= sub { @_; }
$transformer sub { @_; }
Truth table0%0/3
A ||= B
A= $transformerB= sub { @_; }
ABresult
1X1
011
000
75
76 return [ map {
77
78 0 $_ = $transformer->($_)
79
80 0 } @{$self} ]
81
82 }
83  
84  
85 sub list {
86
87 0 ▶ return [@{$_[0]}];
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
88
89 }
90  
91  
92 sub find {
93
94 0 ▶ my ($self, $pattern) = @_;
Subroutine find: not called CC=2 SCAR=17.9
Pod documented
95
96 0 ▶ return undef unless "REGEXP" eq uc ref $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless "REGEXP" eq uc ref $pattern 0 0 0
97
98 0 return ( grep { $_ =~ $pattern } $self->all );
99
100 }
101  
102  
103 sub first {
104
105 0 ▶ my ($self, $pattern) = @_;
Subroutine first: not called CC=2 SCAR=17.9
Pod documented
106
107 0 ▶ return $self->list->[0] unless "REGEXP" eq uc ref $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless "REGEXP" eq uc ref $pattern 0 0 0
108
109 0 return ( $self->find($pattern) )[ 0 ];
110
111 }
112  
113  
114 sub join {
115
116 31 ▶ my ($self, $delimiter) = @_;
Subroutine join: called CC=2 SCAR=7.1
Pod documented
117
118 31 ▶ $delimiter = ', ' unless defined $delimiter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delimiter 0 31 31
119
120 31 return join $delimiter, $self->all;
121
122 }
123  
124  
125 sub to_string {
126
127 31 ▶ my ($self, $delimiter, $transformer) = @_;
Subroutine to_string: called CC=3 SCAR=11.4
Pod documented
128
129 31 ▶ $delimiter = ', ' unless defined $delimiter; # default delimiter is a comma-space
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delimiter 31 0 31
130
131 31 ▶ $self->each($transformer) if $transformer;
Branch: 1 branch
BranchTrueFalseTotal
if $transformer 0 31 31
132
133 31 return $self->join($delimiter);
134  
135 }
136  
137 56 1;
138 __END__
« Class/Base.pm ↑ Summary Class/Collection.pm »