line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package autolocale; |
2
|
2
|
|
|
2
|
|
79881
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
78
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
50
|
use 5.010000; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
92
|
|
5
|
2
|
|
|
2
|
|
1660
|
use POSIX qw(setlocale LC_ALL); |
|
2
|
|
|
|
|
7514
|
|
|
2
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $wiz = wizard( |
10
|
|
|
|
|
|
|
set => sub { |
11
|
|
|
|
|
|
|
my $hinthash = ( caller(0) )[10]; |
12
|
|
|
|
|
|
|
return unless $hinthash->{"autolocale"}; |
13
|
|
|
|
|
|
|
my $arg = shift; |
14
|
|
|
|
|
|
|
if ( ref $arg ne 'SCALAR' ) { |
15
|
|
|
|
|
|
|
die q{You must store scalar data to %ENV}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
my $locale = ${$arg}; |
18
|
|
|
|
|
|
|
return unless $locale; |
19
|
|
|
|
|
|
|
setlocale( LC_ALL, $locale ); |
20
|
|
|
|
|
|
|
return; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
BEGIN { |
25
|
2
|
|
|
2
|
|
1488
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
81
|
|
26
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
549
|
|
27
|
2
|
50
|
|
2
|
|
6
|
if ( eval { require Variable::Magic; 1 } ) { |
|
2
|
|
|
|
|
2125
|
|
|
2
|
|
|
|
|
3048
|
|
28
|
2
|
|
|
|
|
292
|
Variable::Magic->import(qw/wizard cast/); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
|
|
|
|
|
|
# Fallback Pure-Perl mode when can't use Variable::Magic |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
|
|
0
|
package # Hiding package |
34
|
|
|
|
|
|
|
autolocale::Tie::Scalar; |
35
|
0
|
|
|
|
|
0
|
require Tie::Scalar; |
36
|
0
|
|
|
|
|
0
|
our @ISA = qw(Tie::StdScalar); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub STORE { |
39
|
0
|
|
|
0
|
|
0
|
my ( $self, $value ) = @_; |
40
|
0
|
|
|
|
|
0
|
${$self} = $value; |
|
0
|
|
|
|
|
0
|
|
41
|
0
|
|
|
|
|
0
|
@_ = ( \$value ); |
42
|
0
|
|
|
|
|
0
|
goto $wiz; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
*wizard = sub { |
47
|
0
|
|
|
|
|
0
|
my ( undef, $handler ) = @_; |
48
|
0
|
|
|
|
|
0
|
return $handler; |
49
|
0
|
|
|
|
|
0
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
*cast = sub (\$$) { |
52
|
0
|
|
|
|
|
0
|
my $target = shift; |
53
|
0
|
|
|
|
|
0
|
tie $$target, 'autolocale::Tie::Scalar'; |
54
|
0
|
|
|
|
|
0
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub import { |
59
|
4
|
|
|
4
|
|
35
|
$^H{"autolocale"} = 1; |
60
|
4
|
|
|
|
|
2245
|
cast $ENV{"LANG"}, $wiz; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub unimport { |
64
|
1
|
|
|
1
|
|
71
|
$^H{"autolocale"} = 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
autolocale - auto call setlocale() when set $ENV{"LANG"} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use autolocale; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$ENV{"LANG"} = "C"; # locale is "C" |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
local $ENV{"LANG"} = "en_US";# locale is "en_US" |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
# locale is "C" |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
no autolocale; # auto setlocale disabled |
85
|
|
|
|
|
|
|
$ENV{"LANG"} = "en_US"; # locale is "C" |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
autolocale is pragma module that auto call setlocale() when set $ENV{"LANG"}. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Hideaki Ohno E<lt>hide.o.j55 {at} gmail.comE<gt> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
100
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |