| 1 | package Locale::TextDomain::Mock; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 4 | 2 | our $DATE = '2019-12-26'; # DATE | |||||||||
| 5 | 2 | our $DIST = 'Locale-TextDomain-IfEnv'; # DIST | |||||||||
| 6 | 2 | our $VERSION = '0.002'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | #use strict 'subs', 'vars'; | ||||||||||
| 9 | #use warnings; | ||||||||||
| 10 | |||||||||||
| 11 | 8 | ▶ | sub __expand($@) { | ||||||||
|
Subroutine
__expand: called CC=2 SCAR=7.0
| |||||||||||
| 12 | 8 | my ($translation, %args) = @_; | |||||||||
| 13 | 8 | my $re = join '|', map { quotemeta $_ } keys %args; | |||||||||
| 14 | 8 | ▶ | $translation =~ s/\{($re)\}/defined $args{$1} ? $args{$1} : "{$1}"/ge; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 8 | $translation; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | # plain string | ||||||||||
| 19 | 1 | ▶ | sub __($) { | ||||||||
|
Subroutine
__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | $_[0]; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | # interpolation | ||||||||||
| 24 | 2 | ▶ | sub __x($@) { | ||||||||
|
Subroutine
__x: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | goto &__expand; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | # plural | ||||||||||
| 29 | 4 | ▶ | sub __n($$$) { | ||||||||
|
Subroutine
__n: called CC=2 SCAR=6.9
| |||||||||||
| 30 | 4 | my ($msgid, $msgid_plural, $count) = @_; | |||||||||
| 31 | 4 | ▶ | $count > 1 ? $msgid_plural : $msgid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | # plural + interpolation | ||||||||||
| 35 | 6 | ▶ | sub __nx($$$@) { | ||||||||
|
Subroutine
__nx: called CC=2 SCAR=6.9
| |||||||||||
| 36 | 6 | my ($msgid, $msgid_plural, $count, %args) = @_; | |||||||||
| 37 | 6 | ▶ | __expand($count > 1 ? $msgid_plural : $msgid, %args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # alias for __nx | ||||||||||
| 41 | 2 | ▶ | sub __xn($$$@) { | ||||||||
|
Subroutine
__xn: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 2 | goto &__nx; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | # context | ||||||||||
| 46 | 1 | ▶ | sub __p($$) { | ||||||||
|
Subroutine
__p: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 1 | $_[1]; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | # context + interpolation | ||||||||||
| 51 | 1 | ▶ | sub __px($$@) { | ||||||||
|
Subroutine
__px: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 1 | my $context = shift; | |||||||||
| 53 | 1 | goto &__x; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | # context + plural | ||||||||||
| 57 | 2 | ▶ | sub __np($$$$) { | ||||||||
|
Subroutine
__np: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 2 | my $context = shift; | |||||||||
| 59 | 2 | goto &__n; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # context + plural + interpolation | ||||||||||
| 63 | 2 | ▶ | sub __npx($$$$@) { | ||||||||
|
Subroutine
__npx: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 2 | my $context = shift; | |||||||||
| 65 | 2 | goto &__nx; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | # Dummy functions for string marking. | ||||||||||
| 69 | 1 | ▶ | sub N__($) { | ||||||||
|
Subroutine
N__: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 70 | 1 | return shift; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | sub N__n($$$) { | ||||||||
|
Subroutine
N__n: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 74 | 1 | return @_; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | ▶ | sub N__p($$) { | ||||||||
|
Subroutine
N__p: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 78 | 1 | return @_; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | ▶ | sub N__np($$$$) { | ||||||||
|
Subroutine
N__np: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 82 | 1 | return @_; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||
| 86 | 1 | my $class = shift; | |||||||||
| 87 | |||||||||||
| 88 | 1 | my $caller = caller; | |||||||||
| 89 | 1 | for (qw(__ __x __n __nx __xn __p __px __np __npx | |||||||||
| 90 | N__ N__n N__p N__np)) { | ||||||||||
| 91 | 13 | *{"$caller\::$_"} = \&{$_}; | |||||||||
| 92 | } | ||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 2 | 1; | |||||||||
| 96 | # ABSTRACT: Mock Locale::TextDomain functions | ||||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||