Header/MailItem.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 75.0% 15 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 85.7% 72 / 84 CC 12 SCAR 17.2
CC
12
Cov
90%
data
10.3
lines
3.0
extract_msgstr
2.0
CRAP 5.6
↑ Summary Header/ContentTypeItem.pm »
1 package Locale::File::PO::Header::MailItem; ## no critic (TidyCode)
2
3 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 5 our $VERSION = '0.004';
8
9 5 extends qw(Locale::File::PO::Header::Base);
10
11 5 has name => (
12 is => 'rw',
13 isa => 'Str',
14 );
15
16 has mail_name => (
17 is => 'rw',
18 isa => 'Str|Undef',
19 default => q{},
20 19 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
21 19 my ($self, $mail_name, $current_mail_name) = @_;
22
23 19 return $self->trigger_helper({
24 new => $mail_name,
25 current => $current_mail_name,
26 default => q{},
27 writer => 'mail_name',
28 });
29 },
30 5 );
31
32 has mail_address => (
33 is => 'rw',
34 isa => 'Str|Undef',
35 default => q{},
36 21 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 21 my ($self, $mail_address, $current_mail_address) = @_;
38
39 21 return $self->trigger_helper({
40 new => $mail_address,
41 current => $current_mail_address,
42 default => q{},
43 writer => 'mail_address',
44 });
45 },
46 5 );
47
48 9 ▶sub header_keys {
Subroutine header_keys: called CC=1 SCAR=0.0
Pod undocumented
49 9 my $self = shift;
50
51 9 my $name = $self->name;
52
53 9 return "${name}_name", "${name}_address";
54 }
55
56 7 ▶sub data {
Subroutine data: called CC=9 SCAR=23.3
Pod undocumented
57 7 my ($self, $key, @args) = @_;
58
59 7 ▶ defined $key
Branch: 1 branch
BranchTrueFalseTotal
defined $key or confess("Undefined key") 7 0 7
60 or confess 'Undefined key';
61 7 ▶ my $value = @args ? $args[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 6 1 7
62 7 ▶ if ( $key =~ m{ _name \z }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ / _name \z /msx) 3 4 7
63 return
64 @args
65 ? $self->mail_name( # set
66 ref $value eq 'HASH'
67 ? $value->{name}
68 3 ▶ : $value
Branch: 2 branches
BranchTrueFalseTotal
@args ? : 3 0 3
ref $value eq 'HASH' ? : 0 3 3
69 )
70 : $self->mail_name; # get
71 }
72 4 ▶ if ( $key =~ m{ _address \z }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ / _address \z /msx) 4 0 4
73 return
74 @args
75 ? $self->mail_address( # set
76 ref $value eq 'HASH'
77 ? $value->{address}
78 4 ▶ : $value
Branch: 2 branches
BranchTrueFalseTotal
@args ? : 3 1 4
ref $value eq 'HASH' ? : 0 3 3
79 )
80 : $self->mail_address; #get
81 }
82
83 0 confess "Unknown key $key";
84 }
85
86 6 ▶sub extract_msgstr {
Subroutine extract_msgstr: called CC=2 SCAR=6.9
Pod undocumented
87 6 my ($self, $msgstr_ref) = @_;
88
89 6 my $name = $self->name;
90 6 ${$msgstr_ref} =~ s{
91 ^
92 \Q$name\E :
93 \s*
94 ( [^<\n]*? )
95 \s+
96 < ( [^>\n]*? ) >
97 \s*
98 $
99 }{}xmsi
100 6 ▶ || ${$msgstr_ref} =~ s{
Branch: 1 branch
BranchTrueFalseTotal
${$msgstr_ref;} =~ s/ ^ \Q$name\E : \s* ( [^<\n]*? ) \s+ < ( [^>\n]*? ) > \s* $ //imsx or ${$msgstr_ref;} =~ s/ ^ \Q$name\E : \s* ( [^\n]*? ) () \s* $ //imsx 1 5 6
101 ^
102 \Q$name\E :
103 \s*
104 ( [^\n]*? )
105 ()
106 \s*
107 $
108 }{}xmsi;
109 6 $self->mail_name($1); ## no critic (CaptureWithoutTest)
110 6 $self->mail_address($2); ## no critic (CaptureWithoutTest)
111
112 6 return;
113 };
114
115 9 ▶sub lines {
Subroutine lines: called CC=3 SCAR=11.0
Pod undocumented
116 9 my $self = shift;
117
118 9 ▶ if ( ! length $self->mail_name && ! length $self->mail_address ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->mail_name or length $self->mail_address) 4 5 9
Condition66%2/3
length $self->mail_name or length $self->mail_address
l!l&&r!l&&!r
504
MC/DC50%1/2
length $self->mail_name or length $self->mail_address
length $self->mail_name length $self->mail_address
Truth table66%2/3
A or B
A= length $self->mail_nameB= length $self->mail_address
ABresult
1X1
011
000
119 4 return;
120 }
121 5 my $line = $self->format_line(
122 '{name}: {mail_name} <{mail_address}>',
123 name => $self->name,
124 mail_name => $self->mail_name,
125 mail_address => $self->mail_address,
126 );
127 5 $line =~ s{\s* <> \z}{}xms; # delete an empty mail address
128 5 $line =~ s{\s+}{ }xmsg; # delete space before a mail address
129
130 5 return $line;
131 }
132
133 5 __PACKAGE__->meta->make_immutable;
134
135 # $Id: Utils.pm 602 2011-11-13 13:49:23Z steffenw $
136
137 5 1;
↑ Summary Header/ContentTypeItem.pm »