| 1 | package i18n; | ||||||||||||||||||||||||||||
| 2 | 1 | $i18n::VERSION = '0.11'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use constant DATA => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use constant LINE => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use constant PACKAGE => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use constant NEGATED => 3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings::register; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | use overload ( | ||||||||||||||||||||||||||||
| 12 | 1 | '~' => \&_negate, | |||||||||||||||||||||||||||
| 13 | '.' => \&_concat, | ||||||||||||||||||||||||||||
| 14 | '""' => \&_stringify, | ||||||||||||||||||||||||||||
| 15 | fallback => 1, | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub import { | ||||||||||||||||||||||||||||
| 19 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 20 | 1 | my $caller = caller; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | local $@; | |||||||||||||||||||||||||||
| 23 | 1 | ▶ | eval { require Locale::Maketext::Simple; 1 } or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | overload::constant( | ||||||||||||||||||||||||||||
| 26 | q => sub { | ||||||||||||||||||||||||||||
| 27 | 49 | ▶ | shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 49 | pop; | |||||||||||||||||||||||||||
| 29 | 49 | bless( | |||||||||||||||||||||||||||
| 30 | [ | ||||||||||||||||||||||||||||
| 31 | \@_, # DATA | ||||||||||||||||||||||||||||
| 32 | ( caller(1) )[2], # LINE | ||||||||||||||||||||||||||||
| 33 | $caller, # PACKAGE | ||||||||||||||||||||||||||||
| 34 | ], | ||||||||||||||||||||||||||||
| 35 | $class | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | delete ${"$class\::"}{loc}; | |||||||||||||||||||||||||||
| 45 | 1 | delete ${"$class\::"}{loc_lang}; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | unshift @_, 'Path' if @_ % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | Locale::Maketext::Simple->import(@_); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | *{"$caller\::loc"} = $class->can('loc'); | |||||||||||||||||||||||||||
| 51 | 1 | *{"$caller\::loc_lang"} = $class->can('loc_lang'); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | *{"$class\::loc"} = \&_loc; | |||||||||||||||||||||||||||
| 54 | 1 | *{"$class\::loc_lang"} = \&_loc_lang; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | @_ = ( warnings => $class ); | |||||||||||||||||||||||||||
| 58 | 1 | goto &warnings::import; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub unimport { | ||||||||||||||||||||||||||||
| 62 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 1 | overload::remove_constant('q'); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | @_ = ( warnings => $class ); | |||||||||||||||||||||||||||
| 66 | 1 | goto &warnings::unimport; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub loc { goto \&_loc } | ||||||||||||||||||||||||||||
| 70 | sub loc_lang { goto \&_loc_lang } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub _loc { | ||||||||||||||||||||||||||||
| 73 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_loc: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | return $_[0] unless UNIVERSAL::can( $_[0], '_negate' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 1 | goto &_do_loc; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub _loc_lang { | ||||||||||||||||||||||||||||
| 79 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_loc_lang: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 80 | 3 | my $caller = caller; | |||||||||||||||||||||||||||
| 81 | 3 | ▶ | my $loc_lang = $caller->can('loc_lang') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 3 | goto &$loc_lang; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub _negate { | ||||||||||||||||||||||||||||
| 86 | 22 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_negate: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 22 | ▶ | return ~_stringify( $_[0] ) unless warnings::enabled($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 21 | ▶ | goto &_do_loc if $_[0][NEGATED]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | bless( | ||||||||||||||||||||||||||||
| 93 | [ | ||||||||||||||||||||||||||||
| 94 | 11 | [ @{ $_[0][DATA] } ], # DATA | |||||||||||||||||||||||||||
| 95 | $_[0][LINE], # LINE | ||||||||||||||||||||||||||||
| 96 | $_[0][PACKAGE], # PACKAGE | ||||||||||||||||||||||||||||
| 97 | 1, # NEGATED | ||||||||||||||||||||||||||||
| 98 | ], | ||||||||||||||||||||||||||||
| 99 | $class | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub _concat { | ||||||||||||||||||||||||||||
| 104 | 13 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_concat: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 105 | 13 | my $pkg = $_[0][PACKAGE]; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 13 | ▶ | @_ = reverse(@_) if pop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 13 | ▶ | return join( '', @_ ) unless warnings::enabled($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 12 | my $line = (caller)[2]; | |||||||||||||||||||||||||||
| 111 | 12 | my ( $seen, @data ); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 12 | foreach (@_) { | |||||||||||||||||||||||||||
| 114 | 24 | ▶ | ( push( @data, bless( \\$_, "$class\::var" ) ), next ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ and UNIVERSAL::isa($_, $class)
MC/DC50%1/2
ref $_ and UNIVERSAL::isa($_, $class)
ref $_
UNIVERSAL::isa($_, $class)
Truth table66%2/3
A and B
A= ref $_B= UNIVERSAL::isa($_, $class)
| |||||||||||||||||||||||||||||
| 115 | unless ref($_) | ||||||||||||||||||||||||||||
| 116 | and UNIVERSAL::isa( $_, $class ); | ||||||||||||||||||||||||||||
| 117 | 21 | $seen++; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 21 | ▶ | ( push( @data, bless( \\$_, "$class\::var" ) ), next ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_->[1] == $line and not $_->[3]
MC/DC50%1/2
$_->[1] == $line and not $_->[3]
$_->[1] == $line
not $_->[3]
Truth table66%2/3
A and not(B)
A= $_->[1] == $lineB= not $_->[3]
| |||||||||||||||||||||||||||||
| 120 | unless $_->[LINE] == $line and !$_->[NEGATED]; | ||||||||||||||||||||||||||||
| 121 | 14 | $seen++; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 14 | $pkg = $_->[PACKAGE]; | |||||||||||||||||||||||||||
| 124 | 14 | push @data, @{ $_->[DATA] }; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 12 | ▶ | return join( '', @data ) if $seen < 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 12 | return bless( | |||||||||||||||||||||||||||
| 130 | [ | ||||||||||||||||||||||||||||
| 131 | \@data, # DATA | ||||||||||||||||||||||||||||
| 132 | $line, # LINE | ||||||||||||||||||||||||||||
| 133 | $pkg, # PACKAGE | ||||||||||||||||||||||||||||
| 134 | ], | ||||||||||||||||||||||||||||
| 135 | $class | ||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub _stringify { | ||||||||||||||||||||||||||||
| 140 | ( $_[0][NEGATED] ) | ||||||||||||||||||||||||||||
| 141 | 1 | ▶ | ? ~join( '', map { ( ref $_ ) ? "$$$_" : "$_" } @{ $_[0][DATA] } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 44 | ▶ | : join( '', map { ( ref $_ ) ? "$$$_" : "$_" } @{ $_[0][DATA] } ); | ||||||||||||||||||||||||||
|
Subroutine
_stringify: called CC=4 SCAR=13.9
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | sub _do_loc { | ||||||||||||||||||||||||||||
| 146 | 11 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_do_loc: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 147 | 11 | my $pkg = $_[0][PACKAGE]; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 11 | ▶ | ( $pkg eq caller ) and my $loc = $pkg->can('loc') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pkg eq caller and my $loc = $pkg->can("loc")
MC/DC0%0/2
$pkg eq caller and my $loc = $pkg->can("loc")
$pkg eq caller
my $loc = $pkg->can("loc")
Truth table33%1/3
A and B
A= $pkg eq callerB= my $loc = $pkg->can("loc")
| |||||||||||||||||||||||||||||
| 150 | or return ~"$_[0]"; | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 11 | my @vars; | |||||||||||||||||||||||||||
| 153 | my $format = join( | ||||||||||||||||||||||||||||
| 154 | '', | ||||||||||||||||||||||||||||
| 155 | map { | ||||||||||||||||||||||||||||
| 156 | UNIVERSAL::isa( $_, "$class\::var" ) | ||||||||||||||||||||||||||||
| 157 | 9 | ? do { push( @vars, $$$_ ); "[_" . @vars . "]" } | |||||||||||||||||||||||||||
| 158 | 22 | ▶ | : do { my $str = $_; $str =~ s/(?=[\[\]~])/~/g; $str }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 11 | } @{ $_[0][DATA] } | |||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # Defeat constant folding | ||||||||||||||||||||||||||||
| 163 | 11 | ▶ | return bless( [ $loc => $format ], 'i18n::string' ) if !@vars; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 8 | @_ = ( $format, @vars ); | |||||||||||||||||||||||||||
| 166 | 8 | goto &$loc; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | package | ||||||||||||||||||||||||||||
| 170 | i18n::string; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | use overload ( | ||||||||||||||||||||||||||||
| 173 | 1 | '""' => \&_stringify, | |||||||||||||||||||||||||||
| 174 | '0+' => \&_stringify, | ||||||||||||||||||||||||||||
| 175 | fallback => 1, | ||||||||||||||||||||||||||||
| 176 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub _stringify { | ||||||||||||||||||||||||||||
| 179 | 4 | ▶ | $_[0][0]->( $_[0][1] ); | ||||||||||||||||||||||||||
|
Subroutine
_stringify: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | package | ||||||||||||||||||||||||||||
| 183 | i18n::var; | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | use overload ( | ||||||||||||||||||||||||||||
| 186 | 1 | '""' => \&_stringify, | |||||||||||||||||||||||||||
| 187 | '0+' => \&_stringify, | ||||||||||||||||||||||||||||
| 188 | fallback => 1, | ||||||||||||||||||||||||||||
| 189 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub _stringify { ${ ${ $_[0] } } } | ||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||