| 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
Condition66%2/3
not @_ or $_[0]
MC/DC50%1/2
not @_ or $_[0]
not @_
$_[0]
Truth table66%2/3
not(A) or B
A= not @_B= $_[0]
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not @_ or $_[0]
MC/DC50%1/2
not @_ or $_[0]
not @_
$_[0]
Truth table66%2/3
not(A) or B
A= not @_B= $_[0]
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||
| 60 | 161 | for($value) | |||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||
| 62 | 161 | ▶ | s/-\s+/-/ || s/\+\s+//; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 172 | ▶ | return (defined $value && $value =~ /\S/) ? $value : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $value =~ /\S/
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/
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 50 | my $value = $self->internal_value; | |||||||||||||||||||||||||||||||
| 80 | 50 | ▶ | return 1 unless(defined $value && length $value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and length $value
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 49 | ▶ | unless($value =~ $Match) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | if(defined $min && $min >= 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $min and $min >= 0
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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $min and $value < $min
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
| |||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | if($min == 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $max and $value > $max
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||