| 1 | package Validator::Lazy::Role::Check::Required; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 5 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | Validator::Lazy::Role::Check::Required | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | Version 0.03 | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | use Validator::Lazy; | ||||||||||||||||||||||||||||||||||
| 18 | my $v = Validator::Lazy->new( ); | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | my $ok = $v->check( Required => 'xxxxx' ); # ok is true | ||||||||||||||||||||||||||||||||||
| 21 | my $ok = $v->check( Required => '' ); # ok is false | ||||||||||||||||||||||||||||||||||
| 22 | say Dumper $v->errors; # [ { code => 'REQUIRED_ERROR', field => 'Required', data => { } } ] | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | An internal Role for Validator::Lazy, part of Validator::Lazy package. | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | Provides "Required" type for Validator::Lazy config. | ||||||||||||||||||||||||||||||||||
| 30 | Allows to check existance of value. | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | =head2 C<check> | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | Called from inside if Validator::Lazy->check process | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | Temporary overrides internal Validator::Lazy::check method like this: | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | $validator->check( $value, $param ); | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | Empty or undef value is equally make an error. | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =head1 SUPPORT AND DOCUMENTATION | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | After installing, you can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | perldoc Validator::Lazy | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | You can also look for information at: | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | RT, CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||||
| 55 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator-Lazy | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | AnnoCPAN, Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||
| 58 | http://annocpan.org/dist/Validator-Lazy | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | CPAN Ratings | ||||||||||||||||||||||||||||||||||
| 61 | http://cpanratings.perl.org/d/Validator-Lazy | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | Search CPAN | ||||||||||||||||||||||||||||||||||
| 64 | http://search.cpan.org/dist/Validator-Lazy/ | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | ANTONC <antonc@cpan.org> | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||
| 74 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||||||||
| 75 | copy of the full license at: | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | use v5.14.0; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 244 | ▶ | sub before_check { | ||||||||||||||||||||||||||||||||
|
Subroutine
before_check: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 87 | 244 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 244 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | 205 | chomp $value; | |||||||||||||||||||||||||||||||||
| 91 | 205 | $value =~ s/(^\s+|\s+$)//ag; | |||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 244 | return $value; | |||||||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 244 | ▶ | sub check { | ||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 98 | 244 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 244 | ▶ | my $ok = defined $value && ( $value || $value =~ /\d/ ); | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
defined $value && ($value || $value =~ /\d/u)
$value or $value =~ /\d/u
MC/DC100%3/3
defined $value && ($value || $value =~ /\d/u)
defined $value
$value
$value =~ /\d/u
Truth table100%4/4
A && B or C
A= defined $valueB= $valueC= $value =~ /\d/u
| |||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 244 | ▶ | unless ( $ok ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | 44 | $self->add_error( ); | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 244 | return $value; | |||||||||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 5 | 1; | |||||||||||||||||||||||||||||||||