Extract/Role/File.pm

filter: Statementstmt 80.0% 52 / 65 Branchbran 70.0% 7 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 85.7% 12 / 14 Podpod 100% 2 / 2 totaltotal 77.7% 77 / 99 CC 8 SCAR 10.3
CC
8
Cov
78%
__ANON__
6.0
add_message
5.1
__ANON__
3.0
CRAP 2.8
« Extract/HTML.pm ↑ Summary Extract.pm »
1 package Locale::TextDomain::OO::Extract::Role::File; ## no critic (TidyCode)
2
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Locale::TextDomain::OO::Util::JoinSplitLexiconKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Locale::Utils::PlaceholderMaketext;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use MooX::Types::MooseLike::Base qw(ArrayRef Bool HashRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 7 our $VERSION = '2.007';
12
13 7 has category => (
14 is => 'rw',
15 isa => Str,
16 default => q{},
17 );
18
19 7 has domain => (
20 is => 'rw',
21 isa => Str,
22 default => q{},
23 );
24
25 has project => (
26 is => 'rw',
27 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
28 0 my $value = shift;
29 0 ▶ defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return 0 0 0
30 or return;
31 0 Str->($value);
32 0 return;
33 },
34 7 );
35
36 has category_stack => (
37 is => 'rw',
38 isa => ArrayRef,
39 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
40 7 );
41
42 has domain_stack => (
43 is => 'rw',
44 isa => ArrayRef,
45 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 7 );
47
48 7 has filename => (
49 is => 'rw',
50 isa => Str,
51 lazy => 1,
52 default => 'unknown',
53 clearer => '_clear_filename',
54 );
55
56 has lexicon_ref => (
57 is => 'rw',
58 isa => HashRef,
59 lazy => 1,
60 6 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 7 );
62
63 7 has is_maketext_format_gettext => (
64 is => 'ro',
65 isa => Bool,
66 );
67
68 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70
71 0 $self->category( q{} );
72 0 $self->domain( q{} );
73 0 $self->project(undef);
74 0 $self->category_stack([]);
75 0 $self->domain_stack([]);
76 0 $self->_clear_filename;
77
78 0 return;
79 }
80
81 145 ▶my $list_if_length = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
82 145 my ($item, @list) = @_;
83
84 145 ▶ defined $item or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $item or return 135 10 145
85 135 ▶ length $item or return;
Branch: 1 branch
BranchTrueFalseTotal
length $item or return 68 67 135
86
87 68 return @list;
88 7 };
89
90 428 ▶sub add_message {
Subroutine add_message: called CC=5 SCAR=16.4
Pod documented
91 428 my ($self, $msg_ref) = @_;
92
93 428 my $key_util = Locale::TextDomain::OO::Util::JoinSplitLexiconKeys->instance;
94 428 ▶ my $format_util
Condition33%1/3
$self->is_maketext_format_gettext && 'Locale::Utils::PlaceholderMaketext'->new
!ll&&!rl&&r
42800
MC/DC0%0/2
$self->is_maketext_format_gettext && 'Locale::Utils::PlaceholderMaketext'->new
$self->is_maketext_format_gettext 'Locale::Utils::PlaceholderMaketext'->new
Truth table33%1/3
A && B
A= $self->is_maketext_format_gettextB= 'Locale::Utils::PlaceholderMaketext'->new
ABresult
0X0
100
111
95 = $self->is_maketext_format_gettext
96 && Locale::Utils::PlaceholderMaketext->new;
97
98 # build the lexicon part
99 my $lexicon_key = $key_util->join_lexicon_key({(
100 map {
101 428 $_ => $msg_ref->{$_};
102 } qw( category domain project )
103 )});
104 my $lexicon
105 428 ▶ = $self->lexicon_ref->{$lexicon_key}
Condition100%2/2
$self->lexicon_ref->{$lexicon_key} ||= {"", {"msgstr", {"nplurals", 2, "plural", "n != 1"}}}
l!l
41315
MC/DC100%1/1
$self->lexicon_ref->{$lexicon_key} ||= {"", {"msgstr", {"nplurals", 2, "plural", "n != 1"}}}
$self->lexicon_ref->{$lexicon_key}
Truth table100%2/2
A
A= $self->lexicon_ref->{$lexicon_key}
Aresult
11
00
106 ||= {
107 q{} => {
108 msgstr => {
109 nplurals => 2,
110 plural => 'n != 1',
111 }
112 },
113 };
114
115 # build the message part
116 my $msg_key = $key_util->join_message_key({
117 $format_util
118 ? (
119 msgid => $format_util->maketext_to_gettext( $msg_ref->{msgid} ),
120 (
121 map {
122 0 $_ => $msg_ref->{$_};
123 } qw( msgctxt msgid_plural )
124 ),
125 )
126 : (
127 map {
128 428 ▶ $_ => $msg_ref->{$_};
Branch: 1 branch
BranchTrueFalseTotal
$format_util ? : 0 428 428
129 } qw( msgctxt msgid msgid_plural )
130 )
131 });
132 428 ▶ if ( exists $lexicon->{$msg_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lexicon->{$msg_key}) 283 145 428
133 283 $lexicon->{$msg_key}->{reference}->{ $msg_ref->{reference} } = undef;
134 283 return;
135 }
136 $lexicon->{$msg_key} = {
137 $list_if_length->( $msg_ref->{automatic}, automatic => $msg_ref->{automatic} ),
138 reference => { $msg_ref->{reference} => undef },
139 145 };
140
141 145 return;
142 }
143
144 7 1;
145
146 __END__
« Extract/HTML.pm ↑ Summary Extract.pm »