| 1 | package Email::Find; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use vars qw($VERSION @EXPORT); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | $VERSION = "0.10"; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # Need qr//. | ||||||||||||||||||||
| 8 | 3 | require 5.005; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | use base qw(Exporter); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | @EXPORT = qw(find_emails); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | ▶ | use Email::Valid; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 3 | ▶ | use Email::Find::addrspec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 3 | ▶ | use Mail::Address; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 12 | ▶ | sub addr_regex { $Addr_spec_re } | ||||||||||||||||||
|
Subroutine
addr_regex: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | { | ||||||||||||||||||||
| 20 | 3 | my $validator = Email::Valid->new( | |||||||||||||||||||
| 21 | '-fudge' => 0, | ||||||||||||||||||||
| 22 | '-fqdn' => 1, | ||||||||||||||||||||
| 23 | '-local_rules' => 0, | ||||||||||||||||||||
| 24 | '-mxcheck' => 0, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 96 | ▶ | sub do_validate { | ||||||||||||||||||
|
Subroutine
do_validate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 28 | 96 | my($self, $addr) = @_; | |||||||||||||||||||
| 29 | 96 | $validator->address($addr); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 34 | 12 | my($proto, $callback) = @_; | |||||||||||||||||||
| 35 | 12 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 36 | 12 | bless { callback => $callback }, $class; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 12 | ▶ | sub find { | ||||||||||||||||||
|
Subroutine
find: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 40 | 12 | my($self, $r_text) = @_; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 12 | my $emails_found = 0; | |||||||||||||||||||
| 43 | 12 | my $re = $self->addr_regex; | |||||||||||||||||||
| 44 | 12 | $$r_text =~ s{($re)}{ | |||||||||||||||||||
| 45 | 96 | my($replace, $found) = $self->validate($1); | |||||||||||||||||||
| 46 | 96 | $emails_found += $found; | |||||||||||||||||||
| 47 | 96 | $replace; | |||||||||||||||||||
| 48 | }eg; | ||||||||||||||||||||
| 49 | 12 | return $emails_found; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 96 | ▶ | sub validate { | ||||||||||||||||||
|
Subroutine
validate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 53 | 96 | my($self, $orig_match) = @_; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 96 | my $replace; | |||||||||||||||||||
| 56 | 96 | my $found = 0; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # XXX Add cruft handling. | ||||||||||||||||||||
| 59 | 96 | my($start_cruft) = ''; | |||||||||||||||||||
| 60 | 96 | my($end_cruft) = ''; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 96 | ▶ | if( $orig_match =~ s|([),.'";?!]+)$|| ) { #"')){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | $end_cruft = $1; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 96 | ▶ | if( my $email = $self->do_validate($orig_match) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 45 | $email = Mail::Address->new('', $email); | |||||||||||||||||||
| 68 | 45 | $found++; | |||||||||||||||||||
| 69 | 45 | $replace = $start_cruft . $self->{callback}->($email, $orig_match) . $end_cruft; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||
| 72 | # XXX Again with the cruft! | ||||||||||||||||||||
| 73 | 51 | $replace = $start_cruft . $orig_match . $end_cruft; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 96 | return $replace, $found; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | # backward comaptibility | ||||||||||||||||||||
| 79 | 7 | ▶ | sub find_emails(\$&) { | ||||||||||||||||||
|
Subroutine
find_emails: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 80 | 7 | my($r_text, $callback) = @_; | |||||||||||||||||||
| 81 | 7 | my $finder = __PACKAGE__->new($callback); | |||||||||||||||||||
| 82 | 7 | $finder->find($r_text); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 3 | 1; | |||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||