File Coverage

blib/lib/Email/AddressParser.pm
Criterion Covered Total %
statement 32 34 94.1
branch 2 4 50.0
condition n/a
subroutine 10 11 90.9
pod 6 7 85.7
total 50 56 89.2


line stmt bran cond sub pod time code
1             package Email::AddressParser;
2              
3 1     1   29812 use 5.008;
  1         5  
  1         47  
4 1     1   7 use strict;
  1         2  
  1         40  
5 1     1   7 use warnings;
  1         7  
  1         891  
6              
7             require Exporter;
8              
9             our @ISA = qw(Exporter);
10              
11             # Items to export into callers namespace by default. Note: do not export
12             # names by default without a very good reason. Use EXPORT_OK instead.
13             # Do not simply export all your public functions/methods/constants.
14              
15             # This allows declaration use Email::AddressParser ':all';
16             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17             # will save memory.
18             our %EXPORT_TAGS = ( 'all' => [ qw(
19            
20             ) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23              
24             our @EXPORT = qw(
25            
26             );
27              
28             our $VERSION = '0.04';
29              
30             require XSLoader;
31             XSLoader::load('Email::AddressParser', $VERSION);
32              
33             sub new {
34 1     1 1 20 bless { personal => $_[1],
35             email => $_[2],
36             comment => $_[3],
37             original => $_[4],
38             }, $_[0];
39             }
40              
41             sub phrase
42             {
43 1     1 1 195 my $this = shift;
44              
45 1         4 return $this->{personal};
46             }
47              
48             sub original
49             {
50 1     1 0 2 my $this = shift;
51              
52 1         2 return $this->format;
53             }
54              
55             sub address
56             {
57 1     1 1 2 my $this = shift;
58 1         5 return $this->{email};
59             }
60              
61             sub format
62             {
63 3     3 1 8 my $this = shift;
64 3 50       13 if($this->{personal}) {
65 3         11 return _quoted_phrase($this->{personal}) . " <" . $this->{email} . ">";
66             } else {
67 0         0 return $this->{email};
68             }
69             }
70              
71 0     0 1 0 sub comment { "" }
72              
73             sub parse
74             {
75 2     2 1 4 my $class = shift;
76 2         4 my $data = shift;
77 2         66 my $arr = internal_parse($data);
78 2         5 my @rv = ();
79              
80 2         4 for my $v (@$arr) {
81 5         7 bless $v, "Email::AddressParser";
82 5         14 push @rv, $v;
83             }
84              
85 2         23 return @rv;
86             }
87              
88             sub _quoted_phrase {
89 3     3   4 my $phrase = shift;
90              
91 3 50       7 return $phrase if $phrase =~ /\A=\?.+\?=\z/;
92              
93 3         6 $phrase =~ s/\A"(.+)"\z/$1/;
94 3         4 $phrase =~ s/\"/\\"/g;
95              
96 3         23 return qq{"$phrase"};
97             }
98              
99             1;
100             __END__