| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::Eparam; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#===================================================================== |
|
4
|
|
|
|
|
|
|
# CGI::Application::Plugin::Eparam |
|
5
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
6
|
|
|
|
|
|
|
# make : 2005/06/22 aska |
|
7
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
8
|
|
|
|
|
|
|
# $Id$ |
|
9
|
|
|
|
|
|
|
#===================================================================== |
|
10
|
1
|
|
|
1
|
|
24878
|
use 5.004; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
38
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
212
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::VERSION = '0.04'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
|
17
|
1
|
|
|
1
|
|
10
|
my $class = shift; |
|
18
|
1
|
|
|
|
|
2
|
my $caller = caller; |
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
2
|
$CGI::Application::Plugin::Eparam::debug = undef; |
|
21
|
1
|
|
|
|
|
1
|
$CGI::Application::Plugin::Eparam::econv = undef; |
|
22
|
1
|
|
|
|
|
1
|
$CGI::Application::Plugin::Eparam::icode = undef; |
|
23
|
1
|
|
|
|
|
2
|
$CGI::Application::Plugin::Eparam::ocode = undef; |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
$CGI::Application::Plugin::Eparam::temp_econv = undef; |
|
26
|
1
|
|
|
|
|
1
|
$CGI::Application::Plugin::Eparam::temp_icode = undef; |
|
27
|
1
|
|
|
|
|
2
|
$CGI::Application::Plugin::Eparam::temp_ocode = undef; |
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
489
|
|
|
30
|
1
|
|
|
|
|
2
|
*{$caller.'::eparam'} = \&eparam; |
|
|
1
|
|
|
|
|
11
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#===================================================================== |
|
35
|
|
|
|
|
|
|
# Get Value |
|
36
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
|
37
|
|
|
|
|
|
|
# args :key |
|
38
|
|
|
|
|
|
|
# return :convert value |
|
39
|
|
|
|
|
|
|
# example :my $val = $self->eparam('key'); |
|
40
|
|
|
|
|
|
|
#===================================================================== |
|
41
|
|
|
|
|
|
|
sub eparam { |
|
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless ( $CGI::Application::Plugin::Eparam::econv ) { |
|
45
|
0
|
0
|
|
|
|
|
if ( $Encode::VERSION ) { # Encode.pm |
|
|
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::econv = |
|
47
|
0
|
|
|
0
|
|
|
sub { Encode::from_to(${$_[0]},$_[2],$_[1] );}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} elsif ( $Jcode::VERSION ) { # Jcode.pm |
|
49
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::econv = |
|
50
|
0
|
|
|
0
|
|
|
sub { Jcode::convert( $_[0], $_[1], $_[2] ); }; |
|
|
0
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} else { |
|
52
|
0
|
|
|
|
|
|
croak "You must be use Encode or use Jcode or set econv."; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $debug = $CGI::Application::Plugin::Eparam::debug; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
0
|
|
|
|
my $icode = $CGI::Application::Plugin::Eparam::temp_icode || $CGI::Application::Plugin::Eparam::icode; |
|
59
|
0
|
|
0
|
|
|
|
my $ocode = $CGI::Application::Plugin::Eparam::temp_ocode || $CGI::Application::Plugin::Eparam::ocode; |
|
60
|
0
|
|
0
|
|
|
|
my $econv = $CGI::Application::Plugin::Eparam::temp_econv || $CGI::Application::Plugin::Eparam::econv; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
carp "icode:".$icode if $debug; |
|
63
|
0
|
0
|
|
|
|
|
carp "ocode:".$ocode if $debug; |
|
64
|
0
|
0
|
|
|
|
|
carp "econv:".$econv if $debug; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ( !wantarray ) { |
|
67
|
0
|
|
|
|
|
|
my $val = $self->query->param(@_); |
|
68
|
0
|
0
|
0
|
|
|
|
$econv->(\$val, $ocode, $icode) if defined $val && $icode ne $ocode; |
|
69
|
0
|
0
|
|
|
|
|
carp "value:".$val if $debug; |
|
70
|
0
|
|
|
|
|
|
return $val; |
|
71
|
|
|
|
|
|
|
} else { |
|
72
|
0
|
|
|
|
|
|
my @val = $self->query->param(@_); |
|
73
|
0
|
0
|
0
|
|
|
|
map { $econv->(\$_, $ocode, $icode) } @val if scalar(@val) && $icode ne $ocode; |
|
|
0
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
carp "value:".join(',', @val) if $debug; |
|
75
|
0
|
|
|
|
|
|
return @val; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 Name |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
CGI::Application::Plugin::Eparam |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
package WebApp |
|
90
|
|
|
|
|
|
|
use Jcode;# or use Encode or $CGI::Application::Plugin::Eparam::econv = sub { ... } |
|
91
|
|
|
|
|
|
|
use CGI::Application::Plugin::Eparam; |
|
92
|
|
|
|
|
|
|
sub cgiapp_init { |
|
93
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'sjis'; # input code |
|
94
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'euc-jp'; # want code |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
package WebApp::Pages::Public |
|
97
|
|
|
|
|
|
|
sub page1 { |
|
98
|
|
|
|
|
|
|
my $self = shift; |
|
99
|
|
|
|
|
|
|
my $data = $self->eparam('data'); # convert data |
|
100
|
|
|
|
|
|
|
my $natural_data = $self->query->param('data'); # data |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 Example |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 Get Value |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
package WebApp::Pages::Public |
|
108
|
|
|
|
|
|
|
sub page1 { |
|
109
|
|
|
|
|
|
|
my $self = shift; |
|
110
|
|
|
|
|
|
|
my $data = $self->eparam('data'); # convert data |
|
111
|
|
|
|
|
|
|
my $natural_data = $self->query->param('data'); # data |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 in Application |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
package WebApp |
|
117
|
|
|
|
|
|
|
use Jcode;# or use Encode or $CGI::Application::Plugin::Eparam::econv = sub { ... } |
|
118
|
|
|
|
|
|
|
use CGI::Application::Plugin::Eparam; |
|
119
|
|
|
|
|
|
|
sub cgiapp_init { |
|
120
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'sjis'; # input code |
|
121
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'euc-jp'; # want code |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 in SubClass |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package WebApp::Pages::Public |
|
127
|
|
|
|
|
|
|
sub setup { |
|
128
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'sjis'; |
|
129
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'euc-jp'; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
package WebApp::Pages::Admin |
|
132
|
|
|
|
|
|
|
sub setup { |
|
133
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'euc-jp'; |
|
134
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'euc-jp'; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 in Method |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
package WebApp::Pages::User::Mailform |
|
140
|
|
|
|
|
|
|
sub mailform { |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# this case is no convert |
|
143
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'jis'; |
|
144
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'jis'; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# The thing used for the character-code conversion before Mail Sending can be done. |
|
147
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::icode = 'sjis'; |
|
148
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::ocode = 'jis'; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 in Part |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
package Myapplication::Pages::User::Mailform |
|
155
|
|
|
|
|
|
|
sub mailform { |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# temp_ocode are given to priority more than ocode. |
|
158
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::temp_icode = 'sjis'; |
|
159
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::temp_ocode = 'jis'; |
|
160
|
|
|
|
|
|
|
my $val_jis = $self->eparam('val'); |
|
161
|
|
|
|
|
|
|
# It returns it. |
|
162
|
|
|
|
|
|
|
undef $CGI::Application::Plugin::Eparam::temp_icode; |
|
163
|
|
|
|
|
|
|
undef $CGI::Application::Plugin::Eparam::temp_ocode; |
|
164
|
|
|
|
|
|
|
my $val_sjis = $self->eparam('val'); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 Convert Logic Customize |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# It is very effective. |
|
171
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::econv = sub { |
|
172
|
|
|
|
|
|
|
my $textref = shift; |
|
173
|
|
|
|
|
|
|
my $ocode = shift; # output character code |
|
174
|
|
|
|
|
|
|
my $icode = shift; # input character code |
|
175
|
|
|
|
|
|
|
# some logic |
|
176
|
|
|
|
|
|
|
Encode::from_to($$textref, 'Guess', $ocode); |
|
177
|
|
|
|
|
|
|
}; |
|
178
|
|
|
|
|
|
|
# It is temporarily effective. |
|
179
|
|
|
|
|
|
|
$CGI::Application::Plugin::Eparam::temp_econv = sub { |
|
180
|
|
|
|
|
|
|
my $textref = shift; |
|
181
|
|
|
|
|
|
|
my $ocode = shift; # output character code |
|
182
|
|
|
|
|
|
|
my $icode = shift; # input character code |
|
183
|
|
|
|
|
|
|
# some logic |
|
184
|
|
|
|
|
|
|
Encode::from_to($$textref, 'Guess', $ocode); |
|
185
|
|
|
|
|
|
|
}; |
|
186
|
|
|
|
|
|
|
# It returns to the processing of the standard. |
|
187
|
|
|
|
|
|
|
undef $CGI::Application::Plugin::Eparam::temp_econv; |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Shinichiro Aska |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |