blib/lib/Rose/HTML/Form/Field/Numeric.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 84.3% 27 / 32 Conditioncond 76.1% 16 / 21 MC/DCmcdc 64.2% 9 / 14 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 87.6% 121 / 138 CC 24 SCAR 19.4
CC
24
Cov
89%
validate
12.2
internal_value
6.0
positive
4.1
CRAP 7.0
« blib/lib/Rose/HTML/Form/Field/Group/OnOff.pm ↑ Summary blib/lib/Rose/HTML/Util.pm »
1 package Rose::HTML::Form::Field::Numeric;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use Rose::HTML::Object::Errors qw(:number);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use base 'Rose::HTML::Form::Field::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '0.624';
10  
11 # use Rose::Object::MakeMethods::Generic
12 # (
13 # scalar => [ qw(min max) ],
14 # );
15  
16 7 __PACKAGE__->default_html_attr_value(size => 6);
17  
18 7 __PACKAGE__->add_required_html_attrs({
19 type => 'number',
20 });
21  
22 sub positive
23 5 ▶{
Subroutine positive: called CC=4 SCAR=14.0
Pod documented
24 5 my($self) = shift;
25  
26 5 ▶ if(!@_ || $_[0])
Branch: 2 branches
BranchTrueFalseTotal
if (not @_ or $_[0]) { } 3 2 5
elsif (@_) { } 2 0 2
Condition66%2/3
not @_ or $_[0]
l!l&&r!l&&!r
032
MC/DC50%1/2
not @_ or $_[0]
not @_ $_[0]
Truth table66%2/3
not(A) or B
A= not @_B= $_[0]
ABresult
1X1
011
000
27 {
28 3 $self->min(0);
29 3 $self->max(undef);
30 }
31 elsif(@_)
32 {
33 2 $self->min(undef);
34 }
35 }
36  
37 sub negative
38 4 ▶{
Subroutine negative: called CC=4 SCAR=14.0
Pod documented
39 4 my($self) = shift;
40  
41 4 ▶ if(!@_ || $_[0])
Branch: 2 branches
BranchTrueFalseTotal
if (not @_ or $_[0]) { } 2 2 4
elsif (@_) { } 2 0 2
Condition66%2/3
not @_ or $_[0]
l!l&&r!l&&!r
022
MC/DC50%1/2
not @_ or $_[0]
not @_ $_[0]
Truth table66%2/3
not(A) or B
A= not @_B= $_[0]
ABresult
1X1
011
000
42 {
43 2 $self->max(0);
44 2 $self->min(undef);
45 }
46 elsif(@_)
47 {
48 2 $self->max(undef);
49 }
50 }
51  
52 sub internal_value
53 172 ▶{
Subroutine internal_value: called CC=6 SCAR=17.9
Pod documented
54 172 my($self) = shift;
55  
56 172 my $value = $self->SUPER::internal_value(@_);
57  
58 172 ▶ if(defined $value)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 161 11 172
59 {
60 161 for($value)
61 {
62 161 ▶ s/-\s+/-/ || s/\+\s+//;
Branch: 1 branch
BranchTrueFalseTotal
s/-\s+/-/ or s/\+\s+// 3 158 161
63 }
64 }
65  
66 172 ▶ return (defined $value && $value =~ /\S/) ? $value : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value =~ /\S/ ? : 157 15 172
Condition100%3/3
defined $value and $value =~ /\S/
!ll&&!rl&&r
114157
MC/DC100%2/2
defined $value and $value =~ /\S/
defined $value $value =~ /\S/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /\S/
ABresult
0X0
100
111
67 }
68  
69 # This is $RE{num}{dec} from Regexp::Common::number
70 7 my $Match = qr{^(?:(?i)(?:[+-]?)(?:(?=[0123456789]|[.])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[+-]?)(?:[0123456789]+))|))$};
71  
72 sub validate
73 51 ▶{
Subroutine validate: called CC=12 SCAR=25.0
Pod documented
74 51 my($self) = shift;
75  
76 51 my $ok = $self->SUPER::validate(@_);
77 51 ▶ return $ok unless($ok);
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 50 51
78  
79 50 my $value = $self->internal_value;
80 50 ▶ return 1 unless(defined $value && length $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 1 49 50
Condition66%2/3
defined $value and length $value
!ll&&!rl&&r
1049
MC/DC50%1/2
defined $value and length $value
defined $value length $value
Truth table66%2/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
81  
82 49 my $min = $self->min;
83 49 my $max = $self->max;
84  
85 49 ▶ my $name = sub { $self->error_label || $self->name };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$self->error_label or $self->name 16 0 16
86  
87 49 ▶ unless($value =~ $Match)
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /$Match/) 5 44 49
88 {
89 5 ▶ if(defined $min && $min >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and $min >= 0) { } 0 5 5
Condition33%1/3
defined $min and $min >= 0
!ll&&!rl&&r
500
MC/DC0%0/2
defined $min and $min >= 0
defined $min $min >= 0
Truth table33%1/3
A and B
A= defined $minB= $min >= 0
ABresult
0X0
100
111
90 {
91 0 $self->add_error_id(NUM_INVALID_NUMBER_POSITIVE, { label => $name });
92 }
93 else
94 {
95 5 $self->add_error_id(NUM_INVALID_NUMBER, { label => $name });
96 }
97  
98 5 return 0;
99 }
100  
101 44 ▶ if(defined $min && $value < $min)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and $value < $min) 6 38 44
Condition100%3/3
defined $min and $value < $min
!ll&&!rl&&r
19196
MC/DC100%2/2
defined $min and $value < $min
defined $min $value < $min
Truth table100%3/3
A and B
A= defined $minB= $value < $min
ABresult
0X0
100
111
102 {
103 6 ▶ if($min == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($min == 0) { } 4 2 6
104 {
105 4 $self->add_error_id(NUM_NOT_POSITIVE_NUMBER, { label => $name });
106 }
107 else
108 {
109 2 $self->add_error_id(NUM_BELOW_MIN, { label => $name, value => $min });
110 }
111 6 return 0;
112 }
113  
114 38 ▶ if(defined $max && $value > $max)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $value > $max) 4 34 38
Condition100%3/3
defined $max and $value > $max
!ll&&!rl&&r
22124
MC/DC100%2/2
defined $max and $value > $max
defined $max $value > $max
Truth table100%3/3
A and B
A= defined $maxB= $value > $max
ABresult
0X0
100
111
115 {
116 4 $self->add_error_id(NUM_ABOVE_MAX, { label => $name, value => $max });
117 4 return 0;
118 }
119  
120 34 return 1;
121 }
122  
123 7 ▶if(__PACKAGE__->localizer->auto_load_messages)
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->localizer->auto_load_messages) 0 7 7
124 {
125 0 __PACKAGE__->localizer->load_all_messages;
126 }
127  
128 7 ▶use utf8; # The __DATA__ section contains UTF-8 text
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 7 1;
131  
132 __DATA__
« blib/lib/Rose/HTML/Form/Field/Group/OnOff.pm ↑ Summary blib/lib/Rose/HTML/Util.pm »