| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package URI::mid; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 24516 | use 5.008; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 76 |  | 
| 4 | 2 |  |  | 2 |  | 13 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 74 |  | 
| 5 | 2 |  |  | 2 |  | 11 | use warnings; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 76 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 13 | use base qw(URI::cid); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 1077 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 17 | use Carp         (); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 32 |  | 
| 10 | 2 |  |  | 2 |  | 12 | use Scalar::Util (); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1297 |  | 
| 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 |  |  |  |  |  |  | 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. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =cut | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub mid { | 
| 48 | 1 |  |  | 1 | 1 | 945 | my ($self, $new) = @_; | 
| 49 | 1 |  |  |  |  | 7 | my $o = $self->opaque; | 
| 50 | 1 |  |  |  |  | 47 | my ($mid, $cid) = ($o =~ m!^([^/]*)(?:/(.*))?$!); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 1 | 50 |  |  |  | 3 | if ($new) { | 
| 53 | 0 | 0 | 0 |  |  | 0 | $new = $new->mid if ref $new and $new->isa('URI::mid'); | 
| 54 | 0 | 0 |  |  |  | 0 | $self->opaque(defined $cid ? "$mid/$cid" : $mid); | 
| 55 | 0 |  |  |  |  | 0 | return $self; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 1 |  |  |  |  | 8 | $mid; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 mid_uri | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Get just the C component as a L object. Returns | 
| 64 |  |  |  |  |  |  | itself if there is no C. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =cut | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub mid_uri { | 
| 69 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 70 | 0 | 0 |  |  |  | 0 | return $self unless $$self =~ m!/!; | 
| 71 | 0 |  |  |  |  | 0 | URI->new('mid:' . shift->mid); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head2 cid | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Get or set the C as a L object. Accepts a string | 
| 77 |  |  |  |  |  |  | or a L object. Which means you can do stuff like this: | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | $mimepart->header('Content-ID' => $mid->cid->format); | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =cut | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub cid { | 
| 84 | 3 |  |  | 3 | 1 | 6 | my ($self, $new) = @_; | 
| 85 | 3 |  |  |  |  | 7 | my $o = $self->opaque; | 
| 86 | 3 |  |  |  |  | 33 | my ($mid, $cid) = ($o =~ m!^([^/]*)(?:/(.*))?$!); | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 3 | 100 |  |  |  | 8 | if (defined $new) { | 
| 89 | 1 | 50 |  |  |  | 21 | if (ref $new) { | 
| 90 | 0 | 0 | 0 |  |  | 0 | Carp::croak('Must be a string or URI::cid') | 
| 91 |  |  |  |  |  |  | unless Scalar::Util::blessed($new) and $new->isa('URI::cid'); | 
| 92 | 0 |  |  |  |  | 0 | $new = $new->cid; | 
| 93 |  |  |  |  |  |  | } | 
| 94 | 1 |  |  |  |  | 4 | $self->opaque("$mid/$new"); | 
| 95 | 1 |  |  |  |  | 92 | return $self; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 2 | 100 | 66 |  |  | 12 | return unless defined $cid and $cid ne ''; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 4 | 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 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 |  |  |  |  |  |  | sub parse { | 
| 121 | 1 |  |  | 1 | 1 | 406 | my ($self, $string) = @_; | 
| 122 |  |  |  |  |  |  | # ha! learned this trick from DBIx::Class. | 
| 123 | 1 | 50 |  |  |  | 4 | Carp::croak('URI::mid::parse makes no sense in void context') | 
| 124 |  |  |  |  |  |  | unless defined wantarray; | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 1 |  |  |  |  | 13 | my @str = map { /^\s*<([^>]*)>\s*$/; $1 } split /(?<=>)\s*(?=<)/, $string; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 127 |  |  |  |  |  |  |  | 
| 128 | 1 | 50 |  |  |  | 8 | $self = URI->new('mid:') unless ref $self; | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 1 | 50 |  |  |  | 149 | unless (wantarray) { | 
| 131 | 0 |  |  |  |  | 0 | $self->opaque($str[0]); | 
| 132 | 0 |  |  |  |  | 0 | return $self; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 1 |  |  |  |  | 2 | map { URI->new("mid:$_") } @str; | 
|  | 2 |  |  |  |  | 37 |  | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =over 4 | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =item L | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =item L | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =item L | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =item L | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =back | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =head1 AUTHOR | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | Dorian Taylor, C<<  >> | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =head1 BUGS | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | Please report any bugs or feature requests to C | 
| 159 |  |  |  |  |  |  | rt.cpan.org>, or through the web interface at | 
| 160 |  |  |  |  |  |  | L.  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 | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | L | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | L | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =item * Search CPAN | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | L | 
| 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 | 
| 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 |  |  |  |  |  |  | 1; # End of URI::mid |