OO/Plugin/Expand/Gettext/Named.pm

filter: Statementstmt 91.6% 77 / 84 Branchbran 67.6% 23 / 34 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 16 / 18 Podpod 100% 2 / 2 totaltotal 83.9% 120 / 143 CC 19 SCAR 17.9
CC
19
Cov
84%
locn
12.2
Nlocn
12.0
__ANON__
2.1
CRAP 6.0
« OO/Lexicon/Role/File.pm ↑ Summary OO/TiedInterface.pm »
1 package Locale::TextDomain::OO::Plugin::Expand::Gettext::Named; ## no critic (TidyCode)
2
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp qw(cluck confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Locale::Utils::PlaceholderNamed;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 5 our $VERSION = '1.027';
12
13 5 requires qw(
14 translate
15 filter
16 run_filter
17 category
18 domain
19 );
20
21 has _shadow_domains_named => (
22 is => 'rw',
23 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 5 );
25
26 has _shadow_categories_named => (
27 is => 'rw',
28 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
29 5 );
30
31 has expand_gettext_named => (
32 is => 'rw',
33 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 4 return Locale::Utils::PlaceholderNamed->new;
35 },
36 5 );
37
38 4 ▶my $begin_d = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
39 4 my ($self, $domain) = @_;
40
41 4 ▶ defined $domain
Branch: 1 branch
BranchTrueFalseTotal
defined $domain or confess("Domain is not defined") 4 0 4
42 or confess 'Domain is not defined';
43 push
44 4 @{ $self->_shadow_domains_named },
45 $self->domain;
46 4 $self->domain($domain);
47
48 4 return $self;
49 5 };
50
51 4 ▶my $begin_c = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
52 4 my ($self, $category) = @_;
53
54 4 ▶ defined $category
Branch: 1 branch
BranchTrueFalseTotal
defined $category or confess("Category is not defined") 4 0 4
55 or confess 'Category is not defined';
56 push
57 4 @{ $self->_shadow_categories_named },
58 $self->category;
59 4 $self->category($category);
60
61 4 return $self;
62 5 };
63
64 4 ▶my $end_d = sub {
Subroutine __ANON__: called CC=2 SCAR=7.5
65 4 my $self = shift;
66
67 4 ▶ if ( ! @{ $self->_shadow_domains_named } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_shadow_domains_named;}) 0 4 4
68 0 cluck 'Tried to get the domain from stack but no domain is not stored';
69 0 return $self;
70 }
71 4 $self->domain( pop @{ $self->_shadow_domains_named } );
72
73 4 return $self;
74 5 };
75
76 4 ▶my $end_c = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
77 4 my $self = shift;
78
79 4 ▶ if ( ! @{ $self->_shadow_categories_named } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_shadow_categories_named;}) 0 4 4
80 0 cluck 'Tried to get the category from stack but no category is stored',
81 return $self;
82 }
83 4 $self->category( pop @{ $self->_shadow_categories_named } );
84
85 4 return $self;
86 5 };
87
88 21 ▶sub locn {
Subroutine locn: called CC=12 SCAR=25.0
Pod documented
89 21 my ($self, @args) = @_;
90
91 21 ▶ my $arg_ref = ref $args[0] eq 'HASH' ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 1 20 21
92 21 ▶ try {
Subroutine __ANON__: called CC=2 SCAR=6.9
93 21 lock_keys( %{$arg_ref}, qw( category domain context text plural replace ) );
94 exists $arg_ref->{plural}
95 21 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_ref->{"plural"} or return 8 13 21
96 8 lock_keys( %{ $arg_ref->{plural} }, qw( singular plural count ) );
97 }
98 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 confess $_;
100 21 };
101
102 $arg_ref->{domain}
103 21 ▶ and $self->$begin_d( $arg_ref->{domain} );
Branch: 1 branch
BranchTrueFalseTotal
$arg_ref->{"domain"} and $self->$begin_d($arg_ref->{"domain"}) 4 17 21
104 $arg_ref->{category}
105 21 ▶ and $self->$begin_c( $arg_ref->{category} );
Branch: 1 branch
BranchTrueFalseTotal
$arg_ref->{"category"} and $self->$begin_c($arg_ref->{"category"}) 4 17 21
106 my $translation
107 = exists $arg_ref->{text}
108 ? $self->translate(
109 13 ▶ @{$arg_ref}{ qw( context text ) },
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_ref->{'plural'} ? : 8 0 8
110 )
111 : exists $arg_ref->{plural}
112 ? $self->translate(
113 $arg_ref->{context},
114 21 ▶ @{ $arg_ref->{plural} }{ qw( singular plural count ) },
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_ref->{'text'} ? : 13 8 21
115 1,
116 )
117 : q{};
118 $arg_ref->{replace}
119 and $translation = $self->expand_gettext_named->expand_named(
120 $translation,
121 $arg_ref->{replace},
122 21 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$arg_ref->{"replace"} and $translation = $self->expand_gettext_named->expand_named($translation, $arg_ref->{"replace"}) 7 14 21
123 21 ▶ $self->filter
Branch: 1 branch
BranchTrueFalseTotal
$self->filter and $self->run_filter(\$translation) 0 21 21
124 and $self->run_filter(\$translation);
125 21 ▶ if ( exists $arg_ref->{text} || exists $arg_ref->{plural} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_ref->{"text"} or exists $arg_ref->{"plural"}) 21 0 21
Condition66%2/3
exists $arg_ref->{"text"} or exists $arg_ref->{"plural"}
l!l&&r!l&&!r
1380
MC/DC0%0/2
exists $arg_ref->{"text"} or exists $arg_ref->{"plural"}
exists $arg_ref->{"text"} exists $arg_ref->{"plural"}
Truth table66%2/3
A or B
A= exists $arg_ref->{"text"}B= exists $arg_ref->{"plural"}
ABresult
1X1
011
000
126 $arg_ref->{domain}
127 21 ▶ and $self->$end_d;
Branch: 1 branch
BranchTrueFalseTotal
$arg_ref->{"domain"} and $self->$end_d 4 17 21
128 $arg_ref->{category}
129 21 ▶ and $self->$end_c;
Branch: 1 branch
BranchTrueFalseTotal
$arg_ref->{"category"} and $self->$end_c 4 17 21
130 }
131
132 21 return $translation;
133 }
134
135 0 ▶sub Nlocn { ## no critic (Capitalization)
Subroutine Nlocn: not called CC=3 SCAR=24.8
Pod documented
136 0 my (undef, @args) = @_;
137
138 0 ▶ my $arg_ref = ref $args[0] eq 'HASH' ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 0 0 0
139
140 0 ▶ return wantarray ? @args : $args[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
141 }
142
143 5 1;
144
145 __END__
« OO/Lexicon/Role/File.pm ↑ Summary OO/TiedInterface.pm »