| 1 | package Sietima::HeaderURI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Sietima::Policy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Sietima::Types qw(Address AddressFromStr is_Address); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Types::Standard qw(Str is_Str ClassName HashRef Optional); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Type::Params -sigs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Types::URI qw(Uri is_Uri); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Email::Address; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | our $VERSION = '1.1.5'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 12 | # ABSTRACT: annotated URI for list headers | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | has uri => ( | |||||||||||||||||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | isa => Uri, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | has comment => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | ▶ | sub _args_from_address($address, $query={}) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_args_from_address: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | my $uri = URI->new($address->address,'mailto'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 14 | $uri->query_form($query->%*); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 14 | my $comment = $address->comment; | |||||||||||||||||||||||||||||||||||||||||
| 34 | # Email::Address::comment always returns a string in paretheses, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # but we don't want that, since we add them back in as_header_raw | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | $comment =~ s{\A\((.*)\)\z}{$1} if $comment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | uri => $uri, | |||||||||||||||||||||||||||||||||||||||||
| 40 | comment => $comment, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 19 | ▶ | around BUILDARGS => sub($orig, $class, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | ▶ | if (@args != 1 or ref($args[0]) eq 'HASH' and $args[0]->{uri}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@args != 1 or ref $args[0] eq "HASH" and $args[0]{"uri"}
ref $args[0] eq "HASH" and $args[0]{"uri"}
MC/DC66%2/3
@args != 1 or ref $args[0] eq "HASH" and $args[0]{"uri"}
@args != 1
ref $args[0] eq "HASH"
$args[0]{"uri"}
Truth table75%3/4
A or B and C
A= @args != 1B= ref $args[0] eq "HASH"C= $args[0]{"uri"}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | return $class->$orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | my $item = $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | ▶ | if (is_Address($item)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | return _args_from_address($item); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | elsif (is_Uri($item)) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | return { uri => $item }; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ▶ | elsif (is_Str($item) and my $address = AddressFromStr->coerce($item)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
is_Str($item) and my $address = &AddressFromStr()->coerce($item)
MC/DC0%0/2
is_Str($item) and my $address = &AddressFromStr()->coerce($item)
is_Str($item)
my $address = &AddressFromStr()->coerce($item)
Truth table66%2/3
A and B
A= is_Str($item)B= my $address = &AddressFromStr()->coerce($item)
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | return _args_from_address($address); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | return { uri => $item }; | |||||||||||||||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | signature_for new_from_address => ( | |||||||||||||||||||||||||||||||||||||||||
| 66 | method => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | positional => [ | ||||||||||||||||||||||||||||||||||||||||||
| 68 | Address->plus_coercions(AddressFromStr), | ||||||||||||||||||||||||||||||||||||||||||
| 69 | Optional[HashRef], | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub new_from_address($class, $address, $query={}) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_address: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | return $class->new(_args_from_address($address,$query)); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 19 | ▶ | sub as_header_raw($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_header_raw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 19 | my $str = sprintf '<%s>',$self->uri; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | ▶ | if (my $c = $self->comment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | $str .= sprintf ' (%s)',$c; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 19 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||||||||||