| 1 | package Valiant::Validator::Presence; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Valiant::I18N; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | with 'Valiant::Validator::Each'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | has required => (is=>'ro', init_arg=>undef, required=>1, default=>1 ); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | has is_blank => (is=>'ro', required=>1, default=>sub {_t 'is_blank'}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | ▶ | sub normalize_shortcut { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_shortcut: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | my ($class, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | return +{} if $arg eq '1' ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 48 | ▶ | sub validate_each { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_each: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 48 | my ($self, $record, $attribute, $value, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 48 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $value or $value eq "" or $value =~ /^\s+$/
not defined $value or $value eq ""
MC/DC66%2/3
not defined $value or $value eq "" or $value =~ /^\s+$/
not defined $value
$value eq ""
$value =~ /^\s+$/
Truth table75%3/4
not(A) or B or C
A= not defined $valueB= $value eq ""C= $value =~ /^\s+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | not(defined $value) || | ||||||||||||||||||||||||||||||||||||||||||
| 20 | $value eq '' || | ||||||||||||||||||||||||||||||||||||||||||
| 21 | $value =~m/^\s+$/ | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | $record->errors->add($attribute, $self->is_blank, $opts) | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | Valiant::Validator::Presence - Verify that a value is present | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | package Local::Test::Presence; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | use Valiant::Validations; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | has name => (is=>'ro'); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | validates name => ( presence => 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | my $object = Local::Test::Presence->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | $object->validate; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | warn $object->errors->_dump; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | $VAR1 = { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'name' => [ | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'Name can\'t be blank', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | Value must be present (not undefined, not an empty string or a string composed | ||||||||||||||||||||||||||||||||||||||||||
| 58 | only of whitespace). Uses C<is_blank> as the translation tag and you can set | ||||||||||||||||||||||||||||||||||||||||||
| 59 | that to override the message. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =head1 SHORTCUT FORM | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | This validator supports the follow shortcut forms: | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | validates attribute => ( presence => 1, ... ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | Which is the same as: | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | validates attribute => ( | ||||||||||||||||||||||||||||||||||||||||||
| 71 | presence => +{}, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | Not a lot of saved typing but it seems to read better. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 GLOBAL PARAMETERS | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | This validator supports all the standard shared parameters: C<if>, C<unless>, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | C<message>, C<strict>, C<allow_undef>, C<allow_blank>. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | L<Valiant>, L<Valiant::Validator>, L<Valiant::Validator::Each>. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||||||||||||||||