| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 104 | $arg_ref->{category} | ||||||||||||||||||||||||||||
| 105 | 21 | ▶ | and $self->$begin_c( $arg_ref->{category} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | my $translation | ||||||||||||||||||||||||||||
| 107 | = exists $arg_ref->{text} | ||||||||||||||||||||||||||||
| 108 | ? $self->translate( | ||||||||||||||||||||||||||||
| 109 | 13 | ▶ | @{$arg_ref}{ qw( context text ) }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 123 | 21 | ▶ | $self->filter | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | and $self->run_filter(\$translation); | ||||||||||||||||||||||||||||
| 125 | 21 | ▶ | if ( exists $arg_ref->{text} || exists $arg_ref->{plural} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $arg_ref->{"text"} or exists $arg_ref->{"plural"}
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"}
| |||||||||||||||||||||||||||||
| 126 | $arg_ref->{domain} | ||||||||||||||||||||||||||||
| 127 | 21 | ▶ | and $self->$end_d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | $arg_ref->{category} | ||||||||||||||||||||||||||||
| 129 | 21 | ▶ | and $self->$end_c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return wantarray ? @args : $args[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 5 | 1; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||