| 1 | package Data::v; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use List::MoreUtils 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use base 'Data::Header::Fields'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our %v_types = ( | |||||||||||||||||||||||||||||||||||||||||
| 15 | 'VCARD' => 'Data::v::Card', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | return $class->SUPER::new( | |||||||||||||||||||||||||||||||||||||||||
| 21 | tight_folding => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | key_cmp => \&default_key_cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | parent => $class->_default_parent, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 162 | ▶ | sub default_key_cmp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_key_cmp: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 162 | my $a = shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 162 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 162 | $a = lc $a; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 162 | $b = lc $b; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 162 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | if $b =~ qr{^$a (?: ; | $)}xms; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 130 | return $a cmp $b; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | sub decode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | my $any = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | my $return_self = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | $self = $self->new() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if not ref $self; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | my $dhf = $self->SUPER::decode($any); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | my $lines = $dhf->_lines; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | my @v_entries; | |||||||||||||||||||||||||||||||||||||||||
| 53 | my $v_type; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | while (my $line = shift @{$lines}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 84 | ▶ | if ($line->key eq 'BEGIN') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | $v_type = $line->value->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 57 | croak 'unknown v-type "'.$v_type.'"' | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | if not $v_types{$v_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | my $v_data = $v_types{$v_type}->new(); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | my $v_entry = ($v_types{$v_type}.'::Entry')->new( | |||||||||||||||||||||||||||||||||||||||||
| 62 | 'key' => $v_type, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 'value' => $v_data, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 'parent' => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | $v_data->parent($v_entry); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | push @v_entries, $v_entry; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ($line->key eq 'END') { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | ▶ | croak 'BEGIN and END mismatch "'.$v_type.'" ne "'.$line->value->as_string.'"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | if $v_type ne $line->value->as_string; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | $v_type = undef; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 72 | push @{$v_entries[-1]->value->_lines}, $line; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | foreach my $v_entry (@v_entries) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | $v_entry->value->rebless_lines; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if (not $return_self) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return \@v_entries; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | $dhf->_lines(\@v_entries); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | return $dhf; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | ▶ | sub _read_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_lines: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | my $any = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | my $fh = IO::Any->read($any); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # put folded lines to an array http://tools.ietf.org/html/rfc2822#section-2.2.3 | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | my $quoted_printable = 0; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | # folded line | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 208 | ▶ | if (($line =~ m/^\s/xms) or ($quoted_printable and ($lines[-1] =~ m/ = \r? \Z /xms))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line =~ /^\s/msx or $quoted_printable and $lines[-1] =~ / = \r? \Z /msx
$quoted_printable and $lines[-1] =~ / = \r? \Z /msx
MC/DC100%3/3
$line =~ /^\s/msx or $quoted_printable and $lines[-1] =~ / = \r? \Z /msx
$line =~ /^\s/msx
$quoted_printable
$lines[-1] =~ / = \r? \Z /msx
Truth table100%4/4
A or B and C
A= $line =~ /^\s/msxB= $quoted_printableC= $lines[-1] =~ / = \r? \Z /msx
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | # ignore if the first line starts with white space | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 124 | ▶ | next if not @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 124 | $lines[-1] .= $line; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 124 | next; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # detect quoted-printable encoding which continues on a next lines when the line ends with "=" | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 84 | my ($key, $value) = split(/:/, $line, 2); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 84 | my @key_parts = split(/;/, $key); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 84 | shift @key_parts; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 84 | ▶ | $quoted_printable = (any { $_ eq 'encoding=quoted-printable' } map { lc $_; } @key_parts); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 84 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 6 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | sub _default_parent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_parent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | return 'Data::Header::Fields'; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 21 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 21 | ▶ | $self->{'parent'} = shift | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 21 | ▶ | return (ref $self ? $self->{'parent'} : $self->_default_parent); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | package Data::v::Card; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | use base 'Data::v'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | use List::MoreUtils 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 19 | ▶ | sub version { return $_[0]->get_value('version') || '2.1'; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->get_value('version') || '2.1'
MC/DC100%1/1
$_[0]->get_value('version') || '2.1'
$_[0]->get_value('version')
Truth table100%2/2
A
A= $_[0]->get_value('version')
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 6 | ▶ | sub rebless_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rebless_lines: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | foreach my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 153 | 72 | $line = Data::v::Card::Line->new( | |||||||||||||||||||||||||||||||||||||||||
| 154 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | parent => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | sub _default_parent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_parent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | return 'Data::v::Card::Entry'; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 15 | ▶ | sub line_ending { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_ending: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 15 | return $self->parent->parent->line_ending(@_); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 32 | ▶ | sub get_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_fields: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 32 | ▶ | my $field_name = shift or croak 'field_name argument is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 32 | my $param_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 32 | my $param_value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 32 | my @fields = $self->SUPER::get_fields($field_name); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 32 | ▶ | if (defined $param_name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | @fields = | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | grep { any { lc $_->value eq $param_value } $_->get_key_params($param_name) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | @fields | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 32 | return @fields; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | package Data::v::Card::Line; | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | ▶ | use base 'Data::Header::Fields::Line'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | use MIME::QuotedPrint 'encode_qp', 'decode_qp'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | use MIME::Base64 'encode_base64', 'decode_base64'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | ▶ | use List::MoreUtils 'none'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | ▶ | '""' => \&as_string, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 'cmp' => \&Data::Header::Fields::Line::cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 79 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 79 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 79 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||||||||||||||||
| 207 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 79 | $self->_decode_key_params; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 79 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 18 | ▶ | sub version { return $_[0]->parent->version; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 254 | ▶ | sub params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 254 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 254 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 73 | $self->{params} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | $self->{params} = [] | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 254 | ▶ | if (not $self->{params}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 254 | return $self->{params}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 93 | ▶ | sub _decode_key_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_key_params: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 93 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 93 | my $key = $self->key; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 93 | ▶ | if ($key =~ m/^([^;]+);(.+)$/xms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 60 | my $orig_key_name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 60 | my @raw_key_params = split /;/, $2; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 60 | my @key_params; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 60 | my $key_name = lc $orig_key_name; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 60 | foreach my $key_param (@raw_key_params) { | |||||||||||||||||||||||||||||||||||||||||
| 240 | 106 | ▶ | croak 'unknown key param "'.$key_param.'"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | if $key_param !~ m/^ (?: ([^=]+) = )? (.+) $/xms; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 106 | ▶ | my $param_name = $1 || 'TYPE'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || 'TYPE'
MC/DC100%1/1
$1 || 'TYPE'
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 106 | my $param_str = $2; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | push | ||||||||||||||||||||||||||||||||||||||||||
| 246 | @key_params, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 106 | map { Data::v::Param->new('name' => $param_name, 'value' => $_, 'parent' => $self) } | |||||||||||||||||||||||||||||||||||||||||
| 248 | (split(/,/, $param_str)) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 60 | $self->key($orig_key_name); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 60 | $self->params(\@key_params); | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 60 | ▶ | my $enc_type = lc ($self->get_key_param_value('encoding') || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_key_param_value('encoding') || ''
MC/DC100%1/1
$self->get_key_param_value('encoding') || ''
$self->get_key_param_value('encoding')
Truth table100%2/2
A
A= $self->get_key_param_value('encoding')
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 60 | ▶ | if ($enc_type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 10 | ▶ | if ($enc_type eq 'quoted-printable') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | $self->{value} = Data::Header::Fields::Value->new( | ||||||||||||||||||||||||||||||||||||||||||
| 259 | decode_qp($self->{value}) | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | elsif ($enc_type eq 'base64') { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | $self->{value} = Data::Header::Fields::Value->new( | ||||||||||||||||||||||||||||||||||||||||||
| 264 | decode_base64($self->{value}) | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | croak 'unknown encoding "'.$enc_type.'"'; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 60 | ▶ | my $charset = lc ($self->get_key_param_value('charset') || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_key_param_value('charset') || ''
MC/DC100%1/1
$self->get_key_param_value('charset') || ''
$self->get_key_param_value('charset')
Truth table100%2/2
A
A= $self->get_key_param_value('charset')
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | $charset ||= 'utf8' | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 60 | ▶ | if (none { $_ eq $key_name } qw(photo logo sound key)); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%2/2
$charset ||= "utf8"
MC/DC100%1/1
$charset ||= "utf8"
$charset
Truth table100%2/2
A
A= $charset
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 60 | ▶ | if ($charset) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | $self->{'value'} = Data::Header::Fields::Value->new( | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 53 | eval { Encode::decode($charset, $self->{'value'}) } | |||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 93 | ▶ | if ((lc $self->key eq 'n') and (not $self->key->isa('Data::v::Card::Value::Name'))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
lc $self->key eq "n" and not $self->key->isa("Data::v::Card::Value::Name")
MC/DC50%1/2
lc $self->key eq "n" and not $self->key->isa("Data::v::Card::Value::Name")
lc $self->key eq "n"
not $self->key->isa("Data::v::Card::Value::Name")
Truth table66%2/3
A and not(B)
A= lc $self->key eq "n"B= not $self->key->isa("Data::v::Card::Value::Name")
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 9 | $self->{'value'} = Data::v::Card::Value::Name->new( # not calling value() because the set doesn't affect the content of the value | |||||||||||||||||||||||||||||||||||||||||
| 285 | 'value' => $self->value, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 'parent' => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | ▶ | elsif ((lc $self->key eq 'adr') and (not $self->key->isa('Data::v::Card::Value::Adr'))) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
lc $self->key eq "adr" and not $self->key->isa("Data::v::Card::Value::Adr")
MC/DC50%1/2
lc $self->key eq "adr" and not $self->key->isa("Data::v::Card::Value::Adr")
lc $self->key eq "adr"
not $self->key->isa("Data::v::Card::Value::Adr")
Truth table66%2/3
A and not(B)
A= lc $self->key eq "adr"B= not $self->key->isa("Data::v::Card::Value::Adr")
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 9 | $self->{'value'} = Data::v::Card::Value::Adr->new( # not calling value() because the set doesn't affect the content of the value | |||||||||||||||||||||||||||||||||||||||||
| 291 | 'value' => $self->value, | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 'parent' => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 93 | return; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 160 | ▶ | sub get_key_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_params: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 160 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 160 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 160 | my $params = $self->params; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 160 | $param_name = lc $param_name; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 160 | return grep { lc $_->{'name'} eq $param_name } @{$params}; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 146 | ▶ | sub get_key_param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_param: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 146 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 146 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 146 | my @params = $self->get_key_params($param_name); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 146 | ▶ | croak 'more then one key param with name "'.$param_name.'"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | if @params > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 146 | return $params[0]; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 146 | ▶ | sub get_key_param_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_param_value: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 146 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 146 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 146 | my $param = $self->get_key_param($param_name); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 146 | ▶ | return undef if not $param; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 28 | return $param->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | ▶ | sub update_key_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_key_params: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 4 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 4 | my $param_value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # updating via array set | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 4 | ▶ | if (ref $param_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | my @new_params = @{$param_value}; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # update existing | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | foreach my $param (@{$self->params}) { | |||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | ▶ | $param->value(shift @new_params) # will returns undefs if depleeted | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | if ($param->name eq $param_name); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # add any additional new | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | foreach my $add_value (@new_params) { | |||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | push @{$self->{params}}, Data::v::Param->new( | |||||||||||||||||||||||||||||||||||||||||
| 346 | 'parent' => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 'name' => $param_name, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 'value' => $add_value, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | # remove any additional old | ||||||||||||||||||||||||||||||||||||||||||
| 353 | $self->{params} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 6 | grep { defined $_->{'value'} } | |||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | @{$self->{params}} | |||||||||||||||||||||||||||||||||||||||||
| 356 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | my @params = ( | ||||||||||||||||||||||||||||||||||||||||||
| 361 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | ▶ | ($_->{'name'} eq $param_name ? $_->{value} = $param_value : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 3 | $_; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 2 | } @{$self->params} | |||||||||||||||||||||||||||||||||||||||||
| 365 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | ▶ | sub set_key_param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_key_param: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 5 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 5 | my $param_value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 5 | my @params = $self->get_key_params($param_name); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 5 | ▶ | if ((@params > 0) or (ref $param_value)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@params > 0 or ref $param_value
MC/DC100%2/2
@params > 0 or ref $param_value
@params > 0
ref $param_value
Truth table100%3/3
A or B
A= @params > 0B= ref $param_value
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 4 | $self->update_key_params($param_name, $param_value); | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | elsif (@params == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | push @{$self->params}, Data::v::Param->new('name' => $param_name, 'value' => $param_value, 'parent' => $self); | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | croak 'more then one param field with name "'.$param_name.'"'; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | ▶ | sub rm_key_param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rm_key_param: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | my $param_name = shift or croak 'param param_name is mandatory'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | my @params = ( | ||||||||||||||||||||||||||||||||||||||||||
| 394 | grep { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | $_->name ne $param_name | |||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | } @{$self->params} | |||||||||||||||||||||||||||||||||||||||||
| 397 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | $self->params(\@params); | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 14 | ▶ | sub _encode_key_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_key_params: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 14 | my $params = $self->params; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 14 | ▶ | return if scalar @{$params} == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 12 | my $key = $self->key; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | ▶ | my $charset = lc ($self->get_key_param_value('charset') || 'utf8'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_key_param_value('charset') || 'utf8'
MC/DC100%1/1
$self->get_key_param_value('charset') || 'utf8'
$self->get_key_param_value('charset')
Truth table100%2/2
A
A= $self->get_key_param_value('charset')
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | $self->{value} = eval { Encode::encode($charset, $self->{value}) }; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 12 | ▶ | my $enc_type = lc ($self->get_key_param_value('encoding') || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_key_param_value('encoding') || ''
MC/DC100%1/1
$self->get_key_param_value('encoding') || ''
$self->get_key_param_value('encoding')
Truth table100%2/2
A
A= $self->get_key_param_value('encoding')
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 12 | ▶ | if ($enc_type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | ▶ | if ($enc_type eq 'quoted-printable') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | $self->{value} = encode_qp($self->{value}, ""); | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | elsif ($enc_type eq 'base64') { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->{value} = encode_base64($self->{value}, ""); | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | croak 'unknown encoding "'.$enc_type.'"'; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 12 | ▶ | if ($self->version eq '2.1') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | $key .= ';'.( | ||||||||||||||||||||||||||||||||||||||||||
| 428 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 429 | ';', | ||||||||||||||||||||||||||||||||||||||||||
| 430 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 14 | map { $_->as_string } | |||||||||||||||||||||||||||||||||||||||||
| 432 | 15 | grep { defined $_->value } | |||||||||||||||||||||||||||||||||||||||||
| 433 | 8 | @{$params} | |||||||||||||||||||||||||||||||||||||||||
| 434 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 435 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | elsif ($self->version ge '3.0') { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 4 | my @types = map { $_->as_string } $self->get_key_params('type'); | |||||||||||||||||||||||||||||||||||||||||
| 440 | $key .= ';'.( | ||||||||||||||||||||||||||||||||||||||||||
| 441 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 442 | ';', | ||||||||||||||||||||||||||||||||||||||||||
| 443 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 444 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 10 | ▶ | (lc $_->name eq 'type') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | ? ( @types ? ('TYPE='.join(',',splice(@types,0,scalar @types))) : () ) | ||||||||||||||||||||||||||||||||||||||||||
| 447 | : $_->as_string | ||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 10 | grep { defined $_->value } | |||||||||||||||||||||||||||||||||||||||||
| 450 | 4 | @{$params} | |||||||||||||||||||||||||||||||||||||||||
| 451 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 452 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 453 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | croak 'unsupported VCARD version '.$self->version; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 12 | $self->params(undef); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 12 | $self->key($key); | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 68 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 68 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 68 | ▶ | if (exists $self->{'original_line'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 54 | my $original_line = $self->{'original_line'}; | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | # make sure the line has line_ending, even the original one could be created without using ->new() | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 54 | ▶ | $original_line .= $self->parent->line_ending | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | if $original_line !~ m/ \n \Z /xms; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 54 | return $original_line; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 14 | $self->_encode_key_params; | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 14 | my ($key, $value) = ($self->key, $self->value); | |||||||||||||||||||||||||||||||||||||||||
| 481 | #$value = String::Escape::printable($value); | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # FIXME ^^^ should be moved to _encode_key_params | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 14 | my $line = join(':', $key, $value); | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 14 | ▶ | $line .= $self->parent->line_ending | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | if $line !~ m/\n$/xms; | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 14 | $self->_decode_key_params; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 14 | return $line; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | package Data::v::Card::Entry; | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 2 | ▶ | use base 'Data::Header::Fields::Line'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | ▶ | '""' => \&as_string, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 'cmp' => \&Data::Header::Fields::Line::cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ; | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 5 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | return | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 5 | 'BEGIN:VCARD'.$self->parent->line_ending | |||||||||||||||||||||||||||||||||||||||||
| 510 | .$self->value->as_string() | ||||||||||||||||||||||||||||||||||||||||||
| 511 | .'END:VCARD'.$self->parent->line_ending | ||||||||||||||||||||||||||||||||||||||||||
| 512 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | package Data::v::Card::Value::Name; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | use base 'Data::Header::Fields::Value'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | our @NAME_PART_TYPES = qw{family_name given_name additional_names honorific_prefixes honorific_suffixes}; | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | ▶ | '""' => \&Data::Header::Fields::Value::as_string, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 'cmp' => \&Data::Header::Fields::Value::cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | ; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 11 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 11 | ▶ | defined $self->{'value'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | ? $self->_parse_value() | ||||||||||||||||||||||||||||||||||||||||||
| 534 | : $self->_update_value(); | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 3 | ▶ | sub _update_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 3 | my @name_parts = map { $self->$_() } @NAME_PART_TYPES; | |||||||||||||||||||||||||||||||||||||||||
| 543 | # remove the undef fields from the end of the N | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 3 | ▶ | while ((@name_parts) and (not defined $name_parts[-1])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@name_parts and not defined $name_parts[-1]
MC/DC50%1/2
@name_parts and not defined $name_parts[-1]
@name_parts
not defined $name_parts[-1]
Truth table66%2/3
A and not(B)
A= @name_partsB= not defined $name_parts[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 2 | pop @name_parts; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | ▶ | @name_parts = map { defined $_ ? $_ : '' } @name_parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 3 | $self->value(join(';', @name_parts)); | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 10 | ▶ | sub _parse_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 10 | my $name_str = $self->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 558 | 10 | my @name_parts = split(/;/, $name_str); | |||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 10 | foreach my $name_part_type (@NAME_PART_TYPES) { | |||||||||||||||||||||||||||||||||||||||||
| 561 | 50 | my $name_part_value = shift @name_parts; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 50 | $self->{$name_part_type} = $name_part_value; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 4 | ▶ | sub family_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
family_name: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $self->{'family_name'} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 4 | return $self->{'family_name'}; | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 4 | ▶ | sub given_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
given_name: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 4 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->{'given_name'} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 4 | return $self->{'given_name'}; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 5 | ▶ | sub additional_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
additional_names: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | $self->{'additional_names'} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | return $self->{'additional_names'}; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 4 | ▶ | sub honorific_prefixes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
honorific_prefixes: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $self->{'honorific_prefixes'} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 4 | return $self->{'honorific_prefixes'}; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 5 | ▶ | sub honorific_suffixes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
honorific_suffixes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | $self->{'honorific_suffixes'} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 5 | return $self->{'honorific_suffixes'}; | |||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | package Data::v::Card::Value::Adr; | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | ▶ | use base 'Data::Header::Fields::Value'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | our @ADR_PART_TYPES = qw{po_box ext_address street city state postal_code country}; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | ▶ | '""' => \&Data::Header::Fields::Value::as_string, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | 'cmp' => \&Data::Header::Fields::Value::cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | ; | |||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 11 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 11 | ▶ | defined $self->{'value'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | ? $self->_parse_value() | ||||||||||||||||||||||||||||||||||||||||||
| 629 | : $self->_update_value(); | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | 2 | ▶ | sub _update_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_value: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 2 | my @adr_parts = map { $self->$_() } @ADR_PART_TYPES; | |||||||||||||||||||||||||||||||||||||||||
| 638 | # remove the undef fields from the end of the N | ||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | ▶ | while ((@adr_parts) and (not defined $adr_parts[-1])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@adr_parts and not defined $adr_parts[-1]
MC/DC0%0/2
@adr_parts and not defined $adr_parts[-1]
@adr_parts
not defined $adr_parts[-1]
Truth table33%1/3
A and not(B)
A= @adr_partsB= not defined $adr_parts[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | pop @adr_parts; | |||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 2 | ▶ | @adr_parts = map { defined $_ ? $_ : '' } @adr_parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | 2 | $self->value(join(';', @adr_parts)); | |||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 10 | ▶ | sub _parse_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | 10 | my $adr_str = $self->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 10 | $adr_str =~ s/ \r? \n \Z//xms; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 10 | my @adr_parts = split(/;/, $adr_str); | |||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 10 | foreach my $adr_part_type (@ADR_PART_TYPES) { | |||||||||||||||||||||||||||||||||||||||||
| 657 | 70 | my $adr_part_value = shift @adr_parts; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 70 | $self->{$adr_part_type} = $adr_part_value; | |||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 3 | ▶ | sub po_box { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
po_box: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | $self->{'po_box'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 3 | return $self->{'po_box'}; | |||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 3 | ▶ | sub ext_address { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ext_address: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $self->{'ext_address'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 3 | return $self->{'ext_address'}; | |||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | ▶ | sub street { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
street: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $self->{'street'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | 3 | return $self->{'street'}; | |||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 3 | ▶ | sub city { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
city: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | $self->{'city'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | return $self->{'city'}; | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 3 | ▶ | sub state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $self->{'state'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 3 | return $self->{'state'}; | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | ▶ | sub postal_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
postal_code: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | $self->{'postal_code'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | return $self->{'postal_code'}; | |||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 5 | ▶ | sub country { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
country: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 1 | $self->{'country'} = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 729 | 1 | $self->_update_value(); | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 5 | return $self->{'country'}; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | package Data::v::Param; | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 740 | 2 | ▶ | '""' => \&as_string, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 'cmp' => \&Data::Header::Fields::Value::cmp, | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 2 | ; | |||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | 120 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 745 | 120 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 120 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 747 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 748 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | 110 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 110 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | 110 | ▶ | $self->{'name'} = shift @_ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | if (@_); | ||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | 110 | return $self->{'name'}; | |||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 85 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 85 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 85 | ▶ | $self->{'value'} = shift @_ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | if (@_); | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 85 | return $self->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 52 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | 52 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | return | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 52 | ▶ | (lc $self->name eq 'type') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | ? $self->value | ||||||||||||||||||||||||||||||||||||||||||
| 775 | : $self->name.'='.$self->value | ||||||||||||||||||||||||||||||||||||||||||
| 776 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | package Data::v::Calendar; | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 2 | ▶ | use base 'Data::v'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | __END__ | ||||||||||||||||||||||||||||||||||||||||||