mid.pm

filter: Statementstmt 80.7% 42 / 52 Branchbran 40.9% 9 / 22 Conditioncond 22.2% 2 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 65.0% 67 / 103 CC 15 SCAR 18.9
CC
15
Cov
64%
mid
11.8
cid
9.3
mid_uri
6.0
CRAP 6.6
↑ Summary cid.pm »
1 package URI::mid;
2  
3 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use base qw(URI::cid);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 URI::mid - RFC 2392 mid: URI implementation
15  
16 =head1 VERSION
17  
18 Version 0.03
19  
20 =cut
21  
22 3 our $VERSION = '0.03';
23  
24 =head1 SYNOPSIS
25  
26 use URI;
27  
28 my $mid = URI->new('mid:');
29 $mid->mid('1bb1a82c-eb3f-415d-b82f-7fa4c63d2e31@foobar.local');
30  
31 # or, pull it (them) straight from the header:
32  
33 my @mids = URI::mid->parse($email->header('References'));
34  
35 # and put it back
36  
37 $email->header(References => join(' ', map { $_->format } @mids));
38  
39 =head1 METHODS
40  
41 =head2 mid
42  
43 Get or set the literal C<Message-ID>.
44  
45 =cut
46  
47 1 ▶sub mid {
Subroutine mid: called CC=5 SCAR=24.7
Pod documented
48 1 my ($self, $new) = @_;
49 1 my $o = $self->opaque;
50 1 my ($mid, $cid) = ($o =~ m!^([^/]*)(?:/(.*))?$!);
51  
52 1 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 0 1 1
53 0 ▶ $new = $new->mid if ref $new and $new->isa('URI::mid');
Branch: 1 branch
BranchTrueFalseTotal
if ref $new and $new->isa("URI::mid") 0 0 0
Condition0%0/3
ref $new and $new->isa("URI::mid")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $new and $new->isa("URI::mid")
ref $new $new->isa("URI::mid")
Truth table0%0/3
A and B
A= ref $newB= $new->isa("URI::mid")
ABresult
0X0
100
111
54 0 ▶ $self->opaque(defined $cid ? "$mid/$cid" : $mid);
Branch: 1 branch
BranchTrueFalseTotal
defined $cid ? : 0 0 0
55 0 return $self;
56 }
57  
58 1 $mid;
59 }
60  
61 =head2 mid_uri
62  
63 Get just the C<Message-ID> component as a L<URI::mid> object. Returns
64 itself if there is no C<Content-ID>.
65  
66 =cut
67  
68 0 ▶sub mid_uri {
Subroutine mid_uri: not called CC=2 SCAR=17.9
Pod documented
69 0 my $self = shift;
70 0 ▶ return $self unless $$self =~ m!/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $$self =~ m[/] 0 0 0
71 0 URI->new('mid:' . shift->mid);
72 }
73  
74 =head2 cid
75  
76 Get or set the C<Content-ID> as a L<URI::cid> object. Accepts a string
77 or a L<URI::cid> object. Which means you can do stuff like this:
78  
79 $mimepart->header('Content-ID' => $mid->cid->format);
80  
81 =cut
82  
83 3 ▶sub cid {
Subroutine cid: called CC=7 SCAR=22.3
Pod documented
84 3 my ($self, $new) = @_;
85 3 my $o = $self->opaque;
86 3 my ($mid, $cid) = ($o =~ m!^([^/]*)(?:/(.*))?$!);
87  
88 3 ▶ if (defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 1 2 3
89 1 ▶ if (ref $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new) 0 1 1
90 0 ▶ Carp::croak('Must be a string or URI::cid')
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($new) and $new->isa("URI::cid") 0 0 0
Condition0%0/3
builtin::blessed($new) and $new->isa("URI::cid")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($new) and $new->isa("URI::cid")
builtin::blessed($new) $new->isa("URI::cid")
Truth table0%0/3
A and B
A= builtin::blessed($new)B= $new->isa("URI::cid")
ABresult
0X0
100
111
91 unless Scalar::Util::blessed($new) and $new->isa('URI::cid');
92 0 $new = $new->cid;
93 }
94 1 $self->opaque("$mid/$new");
95 1 return $self;
96 }
97  
98 2 ▶ return unless defined $cid and $cid ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid and $cid ne "" 1 1 2
Condition66%2/3
defined $cid and $cid ne ""
!ll&&!rl&&r
101
MC/DC50%1/2
defined $cid and $cid ne ""
defined $cid $cid ne ""
Truth table66%2/3
A and B
A= defined $cidB= $cid ne ""
ABresult
0X0
100
111
99  
100 1 URI->new("cid:$cid");
101 }
102  
103 =head2 parse
104  
105 Parse (i.e., remove the confining angle-brackets from) one or more
106 C<Message-ID> headers. Returns them all in list context, or the first
107 one in scalar context, like so:
108  
109 my $mid = URI::mid->parse($email->header('Message-ID'));
110  
111 my @mids = URI::mid->parse($email->header('References'));
112  
113 # Also works as an instance method:
114  
115 my $mid = URI->new('mid:');
116 $mid->parse($email->header('In-Reply-To'));
117  
118 =cut
119  
120 1 ▶sub parse {
Subroutine parse: called CC=4 SCAR=14.8
Pod documented
121 1 my ($self, $string) = @_;
122 # ha! learned this trick from DBIx::Class.
123 1 ▶ Carp::croak('URI::mid::parse makes no sense in void context')
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 1 1
124 unless defined wantarray;
125  
126 1 my @str = map { /^\s*<([^>]*)>\s*$/; $1 } split /(?<=>)\s*(?=<)/, $string;
127  
128 1 ▶ $self = URI->new('mid:') unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
129  
130 1 ▶ unless (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 1 1
131 0 $self->opaque($str[0]);
132 0 return $self;
133 }
134  
135 1 map { URI->new("mid:$_") } @str;
136 }
137  
138 =head1 SEE ALSO
139  
140 =over 4
141  
142 =item L<URI::cid>
143  
144 =item L<http://tools.ietf.org/html/rfc2392>
145  
146 =item L<Email::Simple>
147  
148 =item L<Email::MIME>
149  
150 =back
151  
152 =head1 AUTHOR
153  
154 Dorian Taylor, C<< <dorian at cpan.org> >>
155  
156 =head1 BUGS
157  
158 Please report any bugs or feature requests to C<bug-uri-mid at
159 rt.cpan.org>, or through the web interface at
160 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=URI-mid>. I will be
161 notified, and then you'll automatically be notified of progress on
162 your bug as I make changes.
163  
164  
165 =head1 SUPPORT
166  
167 You can find documentation for this module with the perldoc command.
168  
169 perldoc URI::mid
170  
171 You can also look for information at:
172  
173 =over 4
174  
175 =item * RT: CPAN's request tracker (report bugs here)
176  
177 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-mid>
178  
179 =item * AnnoCPAN: Annotated CPAN documentation
180  
181 L<http://annocpan.org/dist/URI-mid>
182  
183 =item * CPAN Ratings
184  
185 L<http://cpanratings.perl.org/d/URI-mid>
186  
187 =item * Search CPAN
188  
189 L<http://search.cpan.org/dist/URI-mid/>
190  
191 =back
192  
193 =head1 LICENSE AND COPYRIGHT
194  
195 Copyright 2012 Dorian Taylor.
196  
197 Licensed under the Apache License, Version 2.0 (the "License"); you
198 may not use this file except in compliance with the License. You may
199 obtain a copy of the License at
200  
201 L<http://www.apache.org/licenses/LICENSE-2.0>
202  
203 Unless required by applicable law or agreed to in writing, software
204 distributed under the License is distributed on an "AS IS" BASIS,
205 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
206 implied. See the License for the specific language governing
207 permissions and limitations under the License.
208  
209 =cut
210  
211 3 1; # End of URI::mid
↑ Summary cid.pm »