File Coverage

lib/Perlmazing/Perlmazing/is_email_address.pm
Criterion Covered Total %
statement 6 6 100.0
branch 4 6 66.6
condition 6 6 100.0
subroutine 2 2 100.0
pod 0 1 0.0
total 18 21 85.7


line stmt bran cond sub pod time code
1 1     1   11 use Perlmazing;
  1         3  
  1         6  
2            
3             sub main {
4 33 50   33 0 17205 return 0 unless $_[0];
5 33 50 100     462 return (wantarray ? ($1, $2) : 1) if length($_[0]) <= 254 and $_[0] =~ /
    100 100        
6             # Make captures for user and domain only ($1 and $2), using (?: on any other parenthesis to avoid captures
7             ^
8             ( # Begin first part of email address
9             (?: # Option 1
10             [^<>()[\]\\.,;:\s@\"]+ # Any character NOT in this set, at least one
11             (?:
12             \.[^<>()[\]\\.,;:\s@\"]+ # Followed by any character NOT in these set, starting with dot, in groups from 0 to many
13             )*
14             )
15             |
16             (?: # Option 2
17             ".*?(?
18             )
19             )
20             [ ]*@[ ]*
21             ( # Beginning of second part of email address (domain name or ip address)
22             (?:
23             \[ # If IP address, accepted only between brackets
24             (?: # First group cannot begin in zero. From 1 to 255
25             [1-9] # If it's only one char, from 1 to 9
26             |
27             [1-9][0-9] # If it's 2 chars, from 10 to 99
28             |
29             [1][0-9][0-9] # If it's 3 chars, from 100 to 199
30             |
31             [2][0-4][0-9] # If it's 3 chars, from 200 to 249
32             |
33             [2][5][0-5] # If it's 3 chars, from 250 to 255
34             )
35             \. # Separating dot
36             (?: # Second and third groups can start in zero. From 0 to 255
37             (?:
38             [0-9] # If it's only one char, from 0 to 9
39             |
40             [1-9][0-9] # If it's 2 chars, from 10 to 99
41             |
42             [1][0-9][0-9] # If it's 3 chars, from 100 to 199
43             |
44             [2][0-4][0-9] # If it's 3 chars, from 200 to 249
45             |
46             [2][5][0-5] # If it's 3 chars, from 250 to 255
47             )
48             \. # Separating dot
49             ){2} # This must be present 2 times
50             (?: # Fourth group cannot begin in zero and cannot end in 255. From 1 to 254
51             [1-9] # If it's only one char, from 1 to 9
52             |
53             [1-9][0-9] # If it's 2 chars, from 10 to 99
54             |
55             [1][0-9][0-9] # If it's 3 chars, from 100 to 199
56             |
57             [2][0-4][0-9] # If it's 3 chars, from 200 to 249
58             |
59             [2][5][0-4] # If it's 3 chars, from 250 to 254
60             )
61             # No dot here
62             \]
63             )
64             |
65             (?: # If domain, accept only groups of alphanumeric chars, can contain dashes only between chars
66             (?: # First part also must have a dot for one to n parts
67             (?:
68             [a-zA-Z0-9]{1,2} # If it's one or two chars
69             |
70             [a-zA-Z0-9][a-zA-Z0-9\-]+[a-zA-Z0-9] # If it's 3 or more chars
71             )
72             \. # Trailing dot
73             )+ # One or more times the same
74             [a-zA-Z]{2,} # It must end with only letters, from 2 to n
75             )
76             )
77             $
78             /x and length($1) <= 64;
79 8         17 return 0;
80             }
81            
82             1;