Valiant/Validator/Absence.pm

filter: Statementstmt 100% 15 / 15 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 68.5% 24 / 35 CC 5 SCAR 11.7
CC
5
Cov
76%
validate_each
5.5
normalize_shortcut
2.1
BEGIN
1.0
CRAP 3.2
« Valiant/Proxy/Object.pm ↑ Summary Valiant/Validator/Exclusion.pm »
1 package Valiant::Validator::Absence;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Valiant::I18N;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'Valiant::Validator::Each';
7  
8 1 ▶has is_present => (is=>'ro', required=>1, default=>sub {_t 'is_present'});
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 1 ▶sub normalize_shortcut {
Subroutine normalize_shortcut: called CC=2 SCAR=7.2
Pod undocumented
11 1 my ($class, $arg) = @_;
12 1 ▶ return +{} if $arg eq 1;
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq 1 1 0 1
13 }
14  
15 1 ▶sub validate_each {
Subroutine validate_each: called CC=4 SCAR=17.1
Pod undocumented
16 1 my ($self, $record, $attribute, $value, $options) = @_;
17 1 ▶ unless(
Branch: 1 branch
BranchTrueFalseTotal
unless (not defined $value or $value eq "" or $value =~ /^\s+$/) 1 0 1
Condition33%2/6
not defined $value or $value eq "" or $value =~ /^\s+$/
l!l&&r!l&&!r
001
not defined $value or $value eq ""
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $value or $value eq "" or $value =~ /^\s+$/
not defined $value $value eq "" $value =~ /^\s+$/
Truth table25%1/4
not(A) or B or C
A= not defined $valueB= $value eq ""C= $value =~ /^\s+$/
ABCresult
1XX1
01X1
0011
0000
18 not(defined $value) ||
19 $value eq '' ||
20 $value =~m/^\s+$/
21 ) {
22 1 $record->errors->add($attribute, $self->is_present, $options)
23 }
24 }
25  
26 1 1;
27  
28 =head1 NAME
29  
30 Valiant::Validator::Absence - Verify that a value is missing
31  
32 =head1 SYNOPSIS
33  
34 package Local::Test::Absence;
35  
36 use Moo;
37 use Valiant::Validations;
38  
39 has name => (is=>'ro');
40  
41 validates name => ( absence => 1 );
42  
43 my $object = Local::Test::Absence->new();
44 $object->validate;
45  
46 warn $object->errors->_dump;
47  
48 $VAR1 = {
49 'name' => [
50 'Name must be blank',
51 ]
52 };
53  
54 =head1 DESCRIPTION
55  
56 Value must be absent (undefined, an empty string or a string composed
57 only of whitespace). Uses C<is_present> as the translation tag and you can set
58 that to override the message.
59  
60 =head1 SHORTCUT FORM
61  
62 This validator supports the follow shortcut forms:
63  
64 validates attribute => ( absence => 1, ... );
65  
66 Which is the same as:
67  
68 validates attribute => (
69 absence => +{},
70 );
71  
72 Not a lot of saved typing but it seems to read better.
73
74 =head1 GLOBAL PARAMETERS
75  
76 This validator supports all the standard shared parameters: C<if>, C<unless>,
77 C<message>, C<strict>, C<allow_undef>, C<allow_blank>.
78  
79 =head1 SEE ALSO
80
81 L<Valiant>, L<Valiant::Validator>, L<Valiant::Validator::Each>.
82  
83 =head1 AUTHOR
84
85 See L<Valiant>
86
87 =head1 COPYRIGHT & LICENSE
88
89 See L<Valiant>
90  
91 =cut
« Valiant/Proxy/Object.pm ↑ Summary Valiant/Validator/Exclusion.pm »