| 1 | package Courriel::HeaderAttribute; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | our $VERSION = '0.49'; | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Courriel::HeaderAttribute; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Courriel::Helpers qw( quote_and_escape_attribute_value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Courriel::Types qw( Maybe NonEmptyStr Str ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Encode qw( encode ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | with 'Courriel::Role::Streams'; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | has name => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | has value => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | has charset => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | default => 'us-ascii', | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | has language => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => Maybe [NonEmptyStr], | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 205 | ▶ | override BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 205 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 205 | my $p = super(); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 205 | ▶ | return $p unless defined $p->{value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 205 | ▶ | $p->{charset} = 'UTF-8' if $p->{value} =~ /[^\p{ASCII}]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 205 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | ▶ | sub _stream_to { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stream_to: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | my $output = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | $output->( $self->_as_string ); | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | my $non_attribute_char = qr{ | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | $Courriel::Helpers::TSPECIALS | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | | | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | [ \*\%] # space, *, % | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | | | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | [^\p{ASCII}] # anything that's not ascii | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | | | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | [\x00-\x1f\x7f] # ctrl chars | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | }x; | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ▶ | sub _as_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_as_string: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | my $value = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | my $transport_method = '_simple_parameter'; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | ▶ | if ( $value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/ or defined $self->language or $self->charset ne "us-ascii"
$value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/ or defined $self->language
MC/DC66%2/3
$value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/ or defined $self->language or $self->charset ne "us-ascii"
$value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/
defined $self->language
$self->charset ne "us-ascii"
Truth table75%3/4
A or B or C
A= $value =~ /[\x00-\x1f]|\x7f|[^\p{ASCII}]/B= defined $self->languageC= $self->charset ne "us-ascii"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | || defined $self->language | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | || $self->charset ne 'us-ascii' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | $value = encode( 'utf-8', $value ); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | $value | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 110 | =~ s/($non_attribute_char)/'%' . uc sprintf( '%02x', ord($1) )/eg; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | $transport_method = '_encoded_parameter'; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | elsif ( $value =~ /$non_attribute_char/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $transport_method = '_quoted_parameter'; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # XXX - hard code 78 as the max line length may not be right. Should | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # this account for the length that the parameter name takes up (as | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # well as encoding information, etc.)? | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 10 | my @pieces; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 10 | ▶ | while ( length $value ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 15 | my $last_percent = rindex( $value, '%', 78 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 15 | ▶ | my $size | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | = $last_percent >= 76 ? $last_percent | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | : length $value > 78 ? 78 | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | : length $value; | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 15 | push @pieces, substr( $value, 0, $size, q{} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | ▶ | if ( @pieces == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | return $self->$transport_method( undef, $pieces[0] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | return join q{ }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | map { $self->$transport_method( $_, $pieces[$_] ) } | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 .. $#pieces; | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 10 | ▶ | sub _simple_parameter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_simple_parameter: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | my $order = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | my $param = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | $param .= q{*} . $order if defined $order; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | $param .= q{=}; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | $param .= $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | return $param; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | sub _quoted_parameter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quoted_parameter: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | my $order = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | my $param = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | $param .= q{*} . $order if defined $order; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | $param .= q{=}; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | $value =~ s/\"/\\\"/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | $param .= q{"} . $value . q{"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | return $param; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 7 | ▶ | sub _encoded_parameter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encoded_parameter: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 7 | my $order = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | my $param = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | ▶ | $param .= q{*} . $order if defined $order; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | $param .= q{*=}; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # XXX (1) - does it makes sense to just say everything is utf-8? in theory | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # someone could pass through binary data in another encoding. | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | ▶ | unless ($order) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | ▶ | $param .= 'UTF-8' . q{'} . ( $self->language // q{} ) . q{'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->language // ""
MC/DC100%1/1
$self->language // ""
$self->language
Truth table100%2/2
A
A= $self->language
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 7 | $param .= $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 7 | return $param; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ## use critic; | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # ABSTRACT: A single attribute belonging to a header | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||