| 1 | package FormValidator::Simple::Results; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use base qw/Class::Accessor::Fast/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use FormValidator::Simple::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use FormValidator::Simple::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use FormValidator::Simple::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use List::MoreUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 9 | __PACKAGE__->mk_accessors(qw/_records message/); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 2 | my $self = bless { }, $class; | |||||||||||||||||||||||||||
| 15 | 2 | $self->_init(@_); | |||||||||||||||||||||||||||
| 16 | 2 | return $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 21 | 2 | my %hash = (); | |||||||||||||||||||||||||||
| 22 | 2 | tie (%hash, 'Tie::IxHash'); | |||||||||||||||||||||||||||
| 23 | 2 | $self->_records(\%hash); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | my $messages = delete $args{messages}; | |||||||||||||||||||||||||||
| 26 | 2 | $self->message($messages); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub messages { | ||||||||||||||||||||||||||
|
Subroutine
messages: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my ($self, $action) = @_; | |||||||||||||||||||||||||||
| 31 | 0 | my @messages = (); | |||||||||||||||||||||||||||
| 32 | 0 | my $keys = $self->error; | |||||||||||||||||||||||||||
| 33 | 0 | foreach my $key ( @$keys ) { | |||||||||||||||||||||||||||
| 34 | 0 | my $types = $self->error($key); | |||||||||||||||||||||||||||
| 35 | 0 | foreach my $type ( @$types ) { | |||||||||||||||||||||||||||
| 36 | 0 | push @messages, | |||||||||||||||||||||||||||
| 37 | $self->message->get($action, $key, $type); | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 0 | @messages = List::MoreUtils::uniq(@messages); | |||||||||||||||||||||||||||
| 41 | 0 | return \@messages; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub field_messages { | ||||||||||||||||||||||||||
|
Subroutine
field_messages: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($self, $action) = @_; | |||||||||||||||||||||||||||
| 46 | 0 | my $messages = {}; | |||||||||||||||||||||||||||
| 47 | 0 | my $keys = $self->error; | |||||||||||||||||||||||||||
| 48 | 0 | foreach my $key ( @$keys ) { | |||||||||||||||||||||||||||
| 49 | 0 | $messages->{$key} = []; | |||||||||||||||||||||||||||
| 50 | 0 | my $types = $self->error($key); | |||||||||||||||||||||||||||
| 51 | 0 | foreach my $type ( @$types ) { | |||||||||||||||||||||||||||
| 52 | 0 | my $message = $self->message->get($action, $key, $type); | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | unless ( List::MoreUtils::any { $_ eq $message } @{ $messages->{$key} } ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | push @{ $messages->{$key} }, $message; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | return $messages; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 63 | 3 | ▶ | $self->_records->{$name} | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->_records->{$name} ||= "FormValidator::Simple::Result"->new($name)
MC/DC0%0/2
$self->_records->{$name} ||= "FormValidator::Simple::Result"->new($name)
$self->_records->{$name}
"FormValidator::Simple::Result"->new($name)
Truth table33%1/3
A ||= B
A= $self->_records->{$name}B= "FormValidator::Simple::Result"->new($name)
| |||||||||||||||||||||||||||||
| 64 | ||= FormValidator::Simple::Result->new($name); | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 13 | ▶ | sub record { | ||||||||||||||||||||||||||
|
Subroutine
record: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 13 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 69 | $self->register($name) | ||||||||||||||||||||||||||||
| 70 | 13 | ▶ | unless exists $self->_records->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 13 | return $self->_records->{$name}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub set_result { | ||||||||||||||||||||||||||
|
Subroutine
set_result: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 0 | my ($self, $name, $type, $result) = @_; | |||||||||||||||||||||||||||
| 76 | 0 | $self->register($name); | |||||||||||||||||||||||||||
| 77 | 0 | $self->record($name)->set($type, $result); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub set_invalid { | ||||||||||||||||||||||||||
|
Subroutine
set_invalid: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ($self, $name, $type) = @_; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | unless ($name && $type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name and $type
MC/DC0%0/2
$name and $type
$name
$type
Truth table0%0/3
A and B
A= $nameB= $type
| |||||||||||||||||||||||||||||
| 83 | 0 | FormValidator::Simple::Exception->throw( | |||||||||||||||||||||||||||
| 84 | qq/set_invalid needs two arguments./ | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | $self->set_result($name, $type, FALSE); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub success { | ||||||||||||||||||||||||||
|
Subroutine
success: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | 3 | ▶ | return ($self->has_missing or $self->has_invalid) ? FALSE : TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->has_missing or $self->has_invalid
MC/DC50%1/2
$self->has_missing or $self->has_invalid
$self->has_missing
$self->has_invalid
Truth table66%2/3
A or B
A= $self->has_missingB= $self->has_invalid
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | ▶ | sub has_error { | ||||||||||||||||||||||||||
|
Subroutine
has_error: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 3 | ▶ | return ($self->has_missing or $self->has_invalid) ? TRUE : FALSE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->has_missing or $self->has_invalid
MC/DC50%1/2
$self->has_missing or $self->has_invalid
$self->has_missing
$self->has_invalid
Truth table66%2/3
A or B
A= $self->has_missingB= $self->has_invalid
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 8 | ▶ | sub has_blank { | ||||||||||||||||||||||||||
|
Subroutine
has_blank: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | 8 | foreach my $record ( values %{ $self->_records } ) { | |||||||||||||||||||||||||||
| 103 | 8 | ▶ | return TRUE if $record->is_blank; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 3 | return FALSE; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 9 | *has_missing = \&has_blank; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub has_invalid { | ||||||||||||||||||||||||||
|
Subroutine
has_invalid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 6 | foreach my $record ( values %{ $self->_records } ) { | |||||||||||||||||||||||||||
| 113 | 8 | ▶ | return TRUE if $record->is_invalid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 5 | return FALSE; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 5 | ▶ | sub valid { | ||||||||||||||||||||||||||
|
Subroutine
valid: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 5 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 120 | 5 | ▶ | if ($name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | return unless exists $self->_records->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 1 | ▶ | return $self->record($name)->is_valid | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | ? $self->record($name)->data : FALSE; | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||
| 126 | my %valids | ||||||||||||||||||||||||||||
| 127 | 4 | = map { ( $_->name, $_->data ) } grep { $_->is_valid } values %{ $self->_records }; | |||||||||||||||||||||||||||
| 128 | 4 | return \%valids; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 0 | my ($self, $name, $constraint) = @_; | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($constraint) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($constraint eq 'NOT_BLANK') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return $self->record($name)->is_blank | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | ? TRUE | ||||||||||||||||||||||||||||
| 139 | : FALSE | ||||||||||||||||||||||||||||
| 140 | ; | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return $self->record($name)->is_invalid_for($constraint) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | ? TRUE | ||||||||||||||||||||||||||||
| 144 | : FALSE | ||||||||||||||||||||||||||||
| 145 | ; | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ($self->record($name)->is_blank) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return wantarray ? 'NOT_BLANK' : ['NOT_BLANK']; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | elsif ($self->record($name)->is_invalid) { | ||||||||||||||||||||||||||||
| 152 | 0 | my $constraints = $self->record($name)->constraints; | |||||||||||||||||||||||||||
| 153 | 0 | my @invalids = grep { !$constraints->{$_} } keys %$constraints; | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | return wantarray ? @invalids : \@invalids; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||
| 157 | 0 | return FALSE; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | else { | ||||||||||||||||||||||||||||
| 162 | my @errors = | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | map { $_->name } grep { $_->is_blank or $_->is_invalid } values %{ $self->_records }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_->is_blank || $_->is_invalid
MC/DC0%0/2
$_->is_blank || $_->is_invalid
$_->is_blank
$_->is_invalid
Truth table0%0/3
A || B
A= $_->is_blankB= $_->is_invalid
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return wantarray ? @errors : \@errors; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 3 | ▶ | sub blank { | ||||||||||||||||||||||||||
|
Subroutine
blank: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 170 | 3 | ▶ | if ($name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 1 | ▶ | return $self->record($name)->is_blank ? TRUE : FALSE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||
| 174 | my @blanks | ||||||||||||||||||||||||||||
| 175 | 2 | = map { $_->name } grep { $_->is_blank } values %{ $self->_records }; | |||||||||||||||||||||||||||
| 176 | 2 | ▶ | return wantarray ? @blanks : \@blanks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 9 | *missing = \␣ | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 6 | ▶ | sub invalid { | ||||||||||||||||||||||||||
|
Subroutine
invalid: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 6 | my ($self, $name, $constraint) = @_; | |||||||||||||||||||||||||||
| 184 | 6 | ▶ | if ($name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 5 | ▶ | if ($constraint) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 2 | ▶ | $self->record($name)->is_invalid_for($constraint) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | ? TRUE : FALSE; | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | else { | ||||||||||||||||||||||||||||
| 190 | 3 | ▶ | if ($self->record($name)->is_invalid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 1 | my $constraints = $self->record($name)->constraints; | |||||||||||||||||||||||||||
| 192 | 1 | my @invalids = grep { !$constraints->{$_} } keys %$constraints; | |||||||||||||||||||||||||||
| 193 | 1 | ▶ | return wantarray ? @invalids : \@invalids; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||
| 196 | 2 | return FALSE; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||
| 201 | my @invalids | ||||||||||||||||||||||||||||
| 202 | 1 | = map { $_->name } grep { $_->is_invalid } values %{ $self->_records }; | |||||||||||||||||||||||||||
| 203 | 1 | ▶ | return wantarray ? @invalids : \@invalids; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 208 | 1 | %{shift->_records} = (); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 9 | 1; | |||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||