| 1 | package Validator::Lazy::Role::Check::Email; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | our $VERSION = '0.03'; | |||||||||||
| 4 | |||||||||||||
| 5 | =head1 NAME | ||||||||||||
| 6 | |||||||||||||
| 7 | Validator::Lazy::Role::Check::Email | ||||||||||||
| 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( { email => { Email => $param } } ); # $param is hash, or can be ommitted | ||||||||||||
| 19 | |||||||||||||
| 20 | my $ok = $v->check( email => 'info@info.com' ); # ok is true, $v->errors is empty list | ||||||||||||
| 21 | |||||||||||||
| 22 | my $ok = $v->check( email => 'xxxxxxx' ); # ok is false, $v->errors is empty list | ||||||||||||
| 23 | say Dumper $v->errors; # [ { code => 'EMAIL_ERROR', field => 'email', data => {} ] | ||||||||||||
| 24 | |||||||||||||
| 25 | |||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||
| 27 | |||||||||||||
| 28 | An internal Role for Validator::Lazy, part of Validator::Lazy package. | ||||||||||||
| 29 | |||||||||||||
| 30 | Provides "Email" type for Validator::Lazy config. | ||||||||||||
| 31 | Allows to check value as an Email. | ||||||||||||
| 32 | |||||||||||||
| 33 | When called without param - performs simple check by default | ||||||||||||
| 34 | |||||||||||||
| 35 | =head1 METHODS | ||||||||||||
| 36 | |||||||||||||
| 37 | =head2 C<check> | ||||||||||||
| 38 | Called from inside if Validator::Lazy->check process | ||||||||||||
| 39 | |||||||||||||
| 40 | Temporary overrides internal Validator::Lazy::check method like this: | ||||||||||||
| 41 | |||||||||||||
| 42 | $validator->check( $value, $param ); | ||||||||||||
| 43 | |||||||||||||
| 44 | $param - scalar or list. can contain any 2-letters country code(s) | ||||||||||||
| 45 | $value - your value to check | ||||||||||||
| 46 | |||||||||||||
| 47 | |||||||||||||
| 48 | $param is HASH, that contains this values by default ( if it is not passed ): | ||||||||||||
| 49 | -tldcheck => 1, | ||||||||||||
| 50 | -fudge => 1, | ||||||||||||
| 51 | -fqdn => 1, | ||||||||||||
| 52 | -allow_ip => 0, | ||||||||||||
| 53 | -mxcheck => 0, | ||||||||||||
| 54 | -local_rules => 0, | ||||||||||||
| 55 | |||||||||||||
| 56 | You can pass any of this params. In this case all params, passed by you, will override default ones. | ||||||||||||
| 57 | Detailed description of params you can find in Email::Valid ( https://metacpan.org/pod/Email::Valid ) | ||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | =head1 SUPPORT AND DOCUMENTATION | ||||||||||||
| 61 | |||||||||||||
| 62 | After installing, you can find documentation for this module with the perldoc command. | ||||||||||||
| 63 | |||||||||||||
| 64 | perldoc Validator::Lazy | ||||||||||||
| 65 | |||||||||||||
| 66 | You can also look for information at: | ||||||||||||
| 67 | |||||||||||||
| 68 | RT, CPAN's request tracker (report bugs here) | ||||||||||||
| 69 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator-Lazy | ||||||||||||
| 70 | |||||||||||||
| 71 | AnnoCPAN, Annotated CPAN documentation | ||||||||||||
| 72 | http://annocpan.org/dist/Validator-Lazy | ||||||||||||
| 73 | |||||||||||||
| 74 | CPAN Ratings | ||||||||||||
| 75 | http://cpanratings.perl.org/d/Validator-Lazy | ||||||||||||
| 76 | |||||||||||||
| 77 | Search CPAN | ||||||||||||
| 78 | http://search.cpan.org/dist/Validator-Lazy/ | ||||||||||||
| 79 | |||||||||||||
| 80 | |||||||||||||
| 81 | =head1 AUTHOR | ||||||||||||
| 82 | |||||||||||||
| 83 | ANTONC <antonc@cpan.org> | ||||||||||||
| 84 | |||||||||||||
| 85 | =head1 LICENSE | ||||||||||||
| 86 | |||||||||||||
| 87 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 88 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||
| 89 | copy of the full license at: | ||||||||||||
| 90 | |||||||||||||
| 91 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||
| 94 | |||||||||||||
| 95 | 4 | ▶ | use v5.14.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 96 | 4 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 97 | 4 | ▶ | use Modern::Perl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 98 | 4 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 99 | 4 | ▶ | use Email::Valid; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 100 | |||||||||||||
| 101 | 37 | ▶ | sub check { | ||||||||||
|
Subroutine
check: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||
| 102 | 37 | my ( $self, $value, $param ) = @_; | |||||||||||
| 103 | |||||||||||||
| 104 | 37 | ▶ | return $value unless $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | |||||||||||||
| 106 | my %param = ( | ||||||||||||
| 107 | -tldcheck => 1, | ||||||||||||
| 108 | -fudge => 1, | ||||||||||||
| 109 | -fqdn => 1, | ||||||||||||
| 110 | -allow_ip => 0, | ||||||||||||
| 111 | -mxcheck => 0, | ||||||||||||
| 112 | -local_rules => 0, | ||||||||||||
| 113 | 35 | ▶ | %{ $param // {} }, | ||||||||||
|
Condition50%1/2
$param // {}
MC/DC0%0/1
$param // {}
$param
Truth table50%1/2
A
A= $param
| |||||||||||||
| 114 | ); | ||||||||||||
| 115 | |||||||||||||
| 116 | 35 | my $address = eval{ | |||||||||||
| 117 | 35 | Email::Valid->address( -address => $value, %param ); | |||||||||||
| 118 | }; | ||||||||||||
| 119 | |||||||||||||
| 120 | 35 | ▶ | if ( $@ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | 0 | $self->add_error( { die_reason => $@ } ); | |||||||||||
| 122 | 0 | return $value; | |||||||||||
| 123 | }; | ||||||||||||
| 124 | |||||||||||||
| 125 | 35 | ▶ | unless ( $address ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 126 | # rfc822 localpart local_rules fqdn mxcheck tldcheck | ||||||||||||
| 127 | 3 | my $code = $Email::Valid::Details; | |||||||||||
| 128 | 3 | $self->add_error( { error_code => $code } ); | |||||||||||
| 129 | } | ||||||||||||
| 130 | |||||||||||||
| 131 | 35 | return $value; | |||||||||||
| 132 | }; | ||||||||||||
| 133 | |||||||||||||
| 134 | 4 | 1; | |||||||||||