| 1 | package Labyrinth::Constraints::Emails; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use vars qw($VERSION $AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | $VERSION = '5.32'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Labyrinth::Constraints::Emails - Email Constraint Handler for Labyrinth | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Validates emails, eith in simplistic terms or according to the RFCs. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | # Exporter Settings | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 13 | require Exporter; | |||||||||||||||||||||||||||
| 23 | 13 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 13 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 25 | 13 | @EXPORT = qw( | |||||||||||||||||||||||||||
| 26 | emails valid_emails match_emails | ||||||||||||||||||||||||||||
| 27 | email_rfc valid_email_rfc match_email_rfc | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 31 | # Variables | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # RFC 2396, base definitions. | ||||||||||||||||||||||||||||
| 34 | 13 | my $digit = '[0-9]'; | |||||||||||||||||||||||||||
| 35 | 13 | my $alpha = '[a-zA-Z]'; # lowalpha | upalpha | |||||||||||||||||||||||||||
| 36 | 13 | my $alphanum = '[a-zA-Z0-9]'; # alpha | digit | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 13 | my $IPv4address = qr{ (?: \d+\.\d+\.\d+\.\d+ ) }x; | |||||||||||||||||||||||||||
| 39 | 13 | my $toplabel = qr{ (?: $alpha (?: [-a-zA-Z\d]* $alphanum )? ) }x; | |||||||||||||||||||||||||||
| 40 | 13 | my $domainlabel = qr{ (?: (?: $alphanum [-a-zA-Z\d]*)? $alphanum ) }x; | |||||||||||||||||||||||||||
| 41 | 13 | my $hostname = qr{ (?: (?: $domainlabel\.)+ (?:$toplabel\.)? $alpha{2,} ) }x; | |||||||||||||||||||||||||||
| 42 | 13 | my $host = qr{ (?: $hostname | $IPv4address ) }x; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # RFC 2822, base definitions. | ||||||||||||||||||||||||||||
| 45 | 13 | my $atom_strict = qr{[\w!\#\$\%\&\'\*\+\-\/=\?^\`{|}~]}i; | |||||||||||||||||||||||||||
| 46 | 13 | my $local_strict = qr{$alphanum(?:\.?$atom_strict)*}; | |||||||||||||||||||||||||||
| 47 | 13 | my $local_quoted = qr{\"$local_strict(?:\ $local_strict)*\"}; | |||||||||||||||||||||||||||
| 48 | 13 | my $email_strict = qr{$local_strict\@$host}; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 13 | my $atom_harsh = qr{[\w\'\+\-=]}i; | |||||||||||||||||||||||||||
| 51 | 13 | my $local_harsh = qr{$alphanum(?:\.?$atom_harsh)*}; | |||||||||||||||||||||||||||
| 52 | 13 | my $email_harsh = qr{$local_harsh\@$host}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 55 | # Subroutines | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head2 emails | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Validate email strings against general usage. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over 4 | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item emails | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =item valid_emails | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item match_emails | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =back | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub emails { | ||||||||||||||||||||||||||
|
Subroutine
emails: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 0 | $self->set_current_constraint_name('emails'); | |||||||||||||||||||||||||||
| 80 | 0 | $self->valid_emails($self,\%params); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | } | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 22 | ▶ | sub match_emails { | ||||||||||||||||||||||||||
|
Subroutine
match_emails: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 22 | my ($self,$text) = @_; | |||||||||||||||||||||||||||
| 86 | 22 | ▶ | return unless $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 18 | ▶ | $text =~ m< ^($email_harsh )$ >x ? $1 : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 email_rfc | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Validate email strings against the RFC specs. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =over 4 | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =item email_rfc | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =item valid_email_rfc | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item match_email_rfc | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub email_rfc { | ||||||||||||||||||||||||||
|
Subroutine
email_rfc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | 0 | $self->set_current_constraint_name('email_rfc'); | |||||||||||||||||||||||||||
| 111 | 0 | $self->valid_email_rfc(\%params); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | } | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 22 | ▶ | sub match_email_rfc { | ||||||||||||||||||||||||||
|
Subroutine
match_email_rfc: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 22 | my ($self,$text) = @_; | |||||||||||||||||||||||||||
| 117 | 22 | ▶ | return unless $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 18 | ▶ | $text =~ m< ^( $email_strict )$ >x ? $1 : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 22 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 122 | 22 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 13 | ▶ | no strict qw/refs/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 22 | $name =~ m/^(.*::)(valid_|RE_)(.*)/; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 22 | my ($pkg,$prefix,$sub) = ($1,$2,$3); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Since all the valid_* routines are essentially identical we're | ||||||||||||||||||||||||||||
| 131 | # going to generate them dynamically from match_ routines with the same names. | ||||||||||||||||||||||||||||
| 132 | 22 | ▶ | if ((defined $prefix) and ($prefix eq 'valid_')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $prefix and $prefix eq "valid_"
MC/DC0%0/2
defined $prefix and $prefix eq "valid_"
defined $prefix
$prefix eq "valid_"
Truth table33%1/3
A and B
A= defined $prefixB= $prefix eq "valid_"
| |||||||||||||||||||||||||||||
| 133 | 22 | ▶ | return defined &{$pkg.'match_' . $sub}(@_) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 13 | 1; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||