File Coverage

blib/lib/Mail/Message/Field/URIs.pm
Criterion Covered Total %
statement 42 45 93.3
branch 11 18 61.1
condition 2 3 66.6
subroutine 10 11 90.9
pod 5 6 83.3
total 70 83 84.3


line stmt bran cond sub pod time code
1             # Copyrights 2001-2023 by [Mark Overmeer ].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.03.
5             # This code is part of distribution Mail-Message. Meta-POD processed with
6             # OODoc into POD and HTML manual-pages. See README.md
7             # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8              
9             package Mail::Message::Field::URIs;
10 22     22   817 use vars '$VERSION';
  22         48  
  22         1176  
11             $VERSION = '3.013';
12              
13 22     22   138 use base 'Mail::Message::Field::Structured';
  22         47  
  22         2580  
14              
15 22     22   157 use warnings;
  22         46  
  22         628  
16 22     22   131 use strict;
  22         42  
  22         608  
17              
18 22     22   132 use URI;
  22         56  
  22         11640  
19              
20              
21              
22             sub init($)
23 3     3 0 9 { my ($self, $args) = @_;
24              
25 3         7 my ($body, @body);
26 3 50       13 if($body = delete $args->{body})
27 3 50       29 { @body = ref $body eq 'ARRAY' ? @$body : ($body);
28 3 50       8 return () unless @body;
29             }
30              
31 3         79 $self->{MMFU_uris} = [];
32              
33 3 100 66     18 if(@body > 1 || ref $body[0])
    50          
34 2         11 { $self->addURI($_) foreach @body;
35             }
36             elsif(defined $body)
37 1 50       5 { $body = "<$body>\n" unless index($body, '<') >= 0;
38 1         3 $args->{body} = $body;
39             }
40              
41 3         15 $self->SUPER::init($args);
42             }
43              
44             sub parse($)
45 1     1 1 3 { my ($self, $string) = @_;
46 1         9 my @raw = $string =~ m/\<([^>]+)\>/g; # simply ignore all but <>
47 1         6 $self->addURI($_) foreach @raw;
48 1         4 $self;
49             }
50              
51             sub produceBody()
52 3     3 1 9 { my @uris = sort map { $_->as_string } shift->URIs;
  5         30  
53 3         28 local $" = '>, <';
54 3 50       27 @uris ? "<@uris>" : undef;
55             }
56              
57             #------------------------------------------
58              
59              
60             sub addURI(@)
61 5     5 1 11 { my $self = shift;
62 5 100       18 my $uri = ref $_[0] ? shift : URI->new(@_);
63 5 50       1478 push @{$self->{MMFU_uris}}, $uri->canonical if defined $uri;
  5         28  
64 5         761 delete $self->{MMFF_body};
65 5         14 $uri;
66             }
67              
68              
69 6     6 1 1662 sub URIs() { @{shift->{MMFU_uris}} }
  6         31  
70              
71              
72             sub addAttribute($;@)
73 0     0 1   { my $self = shift;
74 0           $self->log(ERROR => 'No attributes for URI fields.');
75 0           $self;
76             }
77              
78             #------------------------------------------
79              
80              
81             1;