| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not defined $value or $value eq "" or $value =~ /^\s+$/
not defined $value or $value eq ""
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+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||