File Coverage

blib/lib/Mail/Message/Field/URIs.pm
Criterion Covered Total %
statement 44 46 95.6
branch 11 18 61.1
condition 2 3 66.6
subroutine 11 12 91.6
pod 5 6 83.3
total 73 85 85.8


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Message version 4.04.
2             # The POD got stripped from this file by OODoc version 3.06.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2026 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Mail::Message::Field::URIs;{
13             our $VERSION = '4.04';
14             }
15              
16 28     28   1412 use parent 'Mail::Message::Field::Structured';
  28         71  
  28         195  
17              
18 28     28   2470 use warnings;
  28         66  
  28         1624  
19 28     28   151 use strict;
  28         64  
  28         1320  
20              
21 28     28   176 use Log::Report 'mail-message', import => [ qw/__x error/ ];
  28         74  
  28         227  
22              
23 28     28   5333 use URI ();
  28         74  
  28         901  
24 28     28   150 use Scalar::Util qw/blessed/;
  28         80  
  28         21328  
25              
26             #--------------------
27              
28             #--------------------
29              
30             sub init($)
31 7     7 0 18 { my ($self, $args) = @_;
32              
33 7         16 my ($body, @body);
34 7 50       36 if($body = delete $args->{body})
35 7 50       52 { @body = ref $body eq 'ARRAY' ? @$body : ($body);
36 7 50       36 @body or return ();
37             }
38              
39 7         200 $self->{MMFU_uris} = [];
40              
41 7 100 66     59 if(@body > 1 || blessed $body[0])
    50          
42 2         9 { $self->addURI($_) for @body;
43             }
44             elsif(defined $body)
45 5 50       19 { $body = "<$body>\n" unless index($body, '<') >= 0;
46 5         16 $args->{body} = $body;
47             }
48              
49 7         49 $self->SUPER::init($args);
50             }
51              
52             sub parse($)
53 5     5 1 16 { my ($self, $string) = @_;
54 5         43 my @raw = $string =~ m/\<([^>]+)\>/g; # simply ignore all but <>
55 5         27 $self->addURI($_) for @raw;
56 5         18 $self;
57             }
58              
59             sub produceBody()
60 3     3 1 13 { my @uris = sort map $_->as_string, $_[0]->URIs;
61 3         45 local $" = '>, <';
62 3 50       46 @uris ? "<@uris>" : undef;
63             }
64              
65             #--------------------
66              
67             sub addURI(@)
68 9     9 1 21 { my $self = shift;
69 9 100       62 my $uri = blessed $_[0] ? shift : URI->new(@_);
70 9 50       7931 push @{$self->{MMFU_uris}}, $uri->canonical if defined $uri;
  9         62  
71 9         2247 delete $self->{MMFF_body};
72 9         34 $uri;
73             }
74              
75              
76 10     10 1 3055 sub URIs() { @{ $_[0]->{MMFU_uris}} }
  10         87  
77              
78              
79             sub addAttribute($;@)
80 0     0 1   { my $self = shift;
81 0           error __x"no attributes for URI fields.";
82             }
83              
84             #--------------------
85              
86             1;