blib/lib/CGI/Application/Plugin/Eparam.pm

filter: Statementstmt 48.0% 24 / 50 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 1 totaltotal 27.3% 29 / 106 CC 17 SCAR 53.8
CC
17
Cov
28%
eparam
306.0
__ANON__
2.0
__ANON__
2.0
CRAP 217.1
↑ Summary
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 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 $CGI::Application::Plugin::Eparam::VERSION = '0.04';
15  
16 1 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
17 1 my $class = shift;
18 1 my $caller = caller;
19
20 1 $CGI::Application::Plugin::Eparam::debug = undef;
21 1 $CGI::Application::Plugin::Eparam::econv = undef;
22 1 $CGI::Application::Plugin::Eparam::icode = undef;
23 1 $CGI::Application::Plugin::Eparam::ocode = undef;
24  
25 1 $CGI::Application::Plugin::Eparam::temp_econv = undef;
26 1 $CGI::Application::Plugin::Eparam::temp_icode = undef;
27 1 $CGI::Application::Plugin::Eparam::temp_ocode = undef;
28
29 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 *{$caller.'::eparam'} = \&eparam;
31
32 }
33  
34 #=====================================================================
35 # Get Value
36 #---------------------------------------------------------------------
37 # args :key
38 # return :convert value
39 # example :my $val = $self->eparam('key');
40 #=====================================================================
41 0 ▶sub eparam {
Subroutine eparam: not called CC=17 SCAR=57.2
Pod undocumented
42 0 my $self = shift;
43
44 0 ▶ unless ( $CGI::Application::Plugin::Eparam::econv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Application::Plugin::Eparam::econv) 0 0 0
45 0 ▶ if ( $Encode::VERSION ) { # Encode.pm
Branch: 2 branches
BranchTrueFalseTotal
if ($Encode::VERSION) { } 0 0 0
elsif ($Jcode::VERSION) { } 0 0 0
46 $CGI::Application::Plugin::Eparam::econv =
47 0 ▶ sub { Encode::from_to(${$_[0]},$_[2],$_[1] );};
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 } elsif ( $Jcode::VERSION ) { # Jcode.pm
49 $CGI::Application::Plugin::Eparam::econv =
50 0 ▶ sub { Jcode::convert( $_[0], $_[1], $_[2] ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 ▶ my $icode = $CGI::Application::Plugin::Eparam::temp_icode || $CGI::Application::Plugin::Eparam::icode;
Condition0%0/3
$CGI::Application::Plugin::Eparam::temp_icode || $CGI::Application::Plugin::Eparam::icode
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::Eparam::temp_icode || $CGI::Application::Plugin::Eparam::icode
$CGI::Application::Plugin::Eparam::temp_icode $CGI::Application::Plugin::Eparam::icode
Truth table0%0/3
A || B
A= $CGI::Application::Plugin::Eparam::temp_icodeB= $CGI::Application::Plugin::Eparam::icode
ABresult
1X1
011
000
59 0 ▶ my $ocode = $CGI::Application::Plugin::Eparam::temp_ocode || $CGI::Application::Plugin::Eparam::ocode;
Condition0%0/3
$CGI::Application::Plugin::Eparam::temp_ocode || $CGI::Application::Plugin::Eparam::ocode
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::Eparam::temp_ocode || $CGI::Application::Plugin::Eparam::ocode
$CGI::Application::Plugin::Eparam::temp_ocode $CGI::Application::Plugin::Eparam::ocode
Truth table0%0/3
A || B
A= $CGI::Application::Plugin::Eparam::temp_ocodeB= $CGI::Application::Plugin::Eparam::ocode
ABresult
1X1
011
000
60 0 ▶ my $econv = $CGI::Application::Plugin::Eparam::temp_econv || $CGI::Application::Plugin::Eparam::econv;
Condition0%0/3
$CGI::Application::Plugin::Eparam::temp_econv || $CGI::Application::Plugin::Eparam::econv
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::Eparam::temp_econv || $CGI::Application::Plugin::Eparam::econv
$CGI::Application::Plugin::Eparam::temp_econv $CGI::Application::Plugin::Eparam::econv
Truth table0%0/3
A || B
A= $CGI::Application::Plugin::Eparam::temp_econvB= $CGI::Application::Plugin::Eparam::econv
ABresult
1X1
011
000
61
62 0 ▶ carp "icode:".$icode if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
63 0 ▶ carp "ocode:".$ocode if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
64 0 ▶ carp "econv:".$econv if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
65
66 0 ▶ if ( !wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not wantarray) { } 0 0 0
67 0 my $val = $self->query->param(@_);
68 0 ▶ $econv->(\$val, $ocode, $icode) if defined $val && $icode ne $ocode;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and $icode ne $ocode 0 0 0
Condition0%0/3
defined $val and $icode ne $ocode
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $icode ne $ocode
defined $val $icode ne $ocode
Truth table0%0/3
A and B
A= defined $valB= $icode ne $ocode
ABresult
0X0
100
111
69 0 ▶ carp "value:".$val if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
70 0 return $val;
71 } else {
72 0 my @val = $self->query->param(@_);
73 0 ▶ map { $econv->(\$_, $ocode, $icode) } @val if scalar(@val) && $icode ne $ocode;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @val and $icode ne $ocode 0 0 0
Condition0%0/3
scalar @val and $icode ne $ocode
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @val and $icode ne $ocode
scalar @val $icode ne $ocode
Truth table0%0/3
A and B
A= scalar @valB= $icode ne $ocode
ABresult
0X0
100
111
74 0 ▶ carp "value:".join(',', @val) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
75 0 return @val;
76 }
77 }
78  
79 1 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<CGI::Application>
192  
193 =head1 AUTHOR
194  
195 Shinichiro Aska
196  
197 =cut
↑ Summary