| 1 | package autolocale; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use POSIX qw(setlocale LC_ALL); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.07'; | |||||||||
| 8 | |||||||||||
| 9 | my $wiz = wizard( | ||||||||||
| 10 | 0 | ▶ | set => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 11 | 0 | my $hinthash = ( caller(0) )[10]; | |||||||||
| 12 | 0 | ▶ | return unless $hinthash->{"autolocale"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 0 | my $arg = shift; | |||||||||
| 14 | 0 | ▶ | if ( ref $arg ne 'SCALAR' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 0 | die q{You must store scalar data to %ENV}; | |||||||||
| 16 | } | ||||||||||
| 17 | 0 | my $locale = ${$arg}; | |||||||||
| 18 | 0 | ▶ | return unless $locale; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | setlocale( LC_ALL, $locale ); | |||||||||
| 20 | 0 | return; | |||||||||
| 21 | } | ||||||||||
| 22 | 2 | ); | |||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=10.2
| |||||||||||
| 25 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 2 | ▶ | if ( eval { require Variable::Magic; 1 } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 2 | Variable::Magic->import(qw/wizard cast/); | |||||||||
| 29 | } | ||||||||||
| 30 | else { | ||||||||||
| 31 | # Fallback Pure-Perl mode when can't use Variable::Magic | ||||||||||
| 32 | { | ||||||||||
| 33 | package # Hiding package | ||||||||||
| 34 | autolocale::Tie::Scalar; | ||||||||||
| 35 | 0 | require Tie::Scalar; | |||||||||
| 36 | 0 | our @ISA = qw(Tie::StdScalar); | |||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub STORE { | ||||||||
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 0 | my ( $self, $value ) = @_; | |||||||||
| 40 | 0 | ${$self} = $value; | |||||||||
| 41 | 0 | @_ = ( \$value ); | |||||||||
| 42 | 0 | goto $wiz; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | *wizard = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 0 | my ( undef, $handler ) = @_; | |||||||||
| 48 | 0 | return $handler; | |||||||||
| 49 | 0 | }; | |||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | *cast = sub (\$$) { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 52 | 0 | my $target = shift; | |||||||||
| 53 | 0 | tie $$target, 'autolocale::Tie::Scalar'; | |||||||||
| 54 | 0 | }; | |||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 4 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 4 | $^H{"autolocale"} = 1; | |||||||||
| 60 | 4 | cast $ENV{"LANG"}, $wiz; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | sub unimport { | ||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 1 | $^H{"autolocale"} = 0; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 2 | 1; | |||||||||
| 68 | __END__ | ||||||||||