line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jamila; |
2
|
1
|
|
|
1
|
|
19175
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
871
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
1797
|
use CGI; |
|
1
|
|
|
|
|
15119
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
1065
|
use JSON; |
|
1
|
|
|
|
|
11697
|
|
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
822
|
use LWP; |
|
1
|
|
|
|
|
41877
|
|
|
1
|
|
|
|
|
876
|
|
8
|
|
|
|
|
|
|
our $oCgi; |
9
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
# _disp: display about processing class |
13
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
sub _disp($$$) |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
|
|
my ($sClass, $sUrl, $sMod) = @_; |
17
|
0
|
|
|
|
|
|
binmode STDOUT, ':utf8'; |
18
|
0
|
|
|
|
|
|
print "Content-Type: text/html\n\n"; |
19
|
0
|
|
|
|
|
|
print<
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$sClass ($sMod) |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This is $sClass ! |
26
|
|
|
|
|
|
|
for : $sMod at $sUrl |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
EOD |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
32
|
|
|
|
|
|
|
# proc |
33
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
34
|
|
|
|
|
|
|
sub proc($$) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
1
|
|
my($sClass, $sMod) = @_; |
37
|
0
|
|
|
|
|
|
$oCgi = new CGI(); |
38
|
0
|
|
|
|
|
|
my $sPrm = $oCgi->param('_prm'); |
39
|
|
|
|
|
|
|
#1. No '_prm' means default display |
40
|
0
|
0
|
0
|
|
|
|
return $sClass->_disp($oCgi->url(), $sMod) if(!defined($sPrm) || $sPrm eq ''); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#2. _RAW_ |
43
|
0
|
|
|
|
|
|
utf8::decode($sPrm); #become with utf8-flag |
44
|
0
|
|
|
|
|
|
my $oRes = ''; |
45
|
0
|
|
|
|
|
|
my $sMsg = ''; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if($sPrm eq '_RAW_') |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
0
|
|
|
|
my $sMethod = '_raw_' . ($oCgi->param('_method') || ''); |
50
|
|
|
|
|
|
|
eval |
51
|
0
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
|
$oRes = $sMod->$sMethod($oCgi); |
53
|
|
|
|
|
|
|
}; |
54
|
0
|
0
|
|
|
|
|
return unless($@); |
55
|
0
|
|
|
|
|
|
$sMsg = $@; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
0
|
|
|
|
|
if($sPrm) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
|
my $raData = from_json($sPrm); |
62
|
0
|
|
|
|
|
|
my ($sMethod, @aPrm) = @$raData; |
63
|
0
|
0
|
|
|
|
|
if(substr($sMethod, 0, 1) ne '_') |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
eval |
66
|
0
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
|
$oRes = $sMod->$sMethod(@aPrm); |
68
|
|
|
|
|
|
|
}; |
69
|
0
|
0
|
|
|
|
|
if($@) |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
eval |
72
|
0
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
|
eval "require $sMod; import $sMod;"; |
74
|
0
|
|
|
|
|
|
$oRes = $sMod->$sMethod(@aPrm); |
75
|
|
|
|
|
|
|
}; |
76
|
0
|
0
|
|
|
|
|
if($@) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
|
$sMsg = $@; |
79
|
0
|
|
|
|
|
|
$oRes = ''; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
|
$sMsg = "Jamila:: can't call $sMethod"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
|
$sMsg = 'Jamila:: NO PARAM'; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
binmode STDOUT, ':utf8'; |
94
|
0
|
|
|
|
|
|
print "Content-Type: text/plain; charset=UTF-8\n\n" . |
95
|
|
|
|
|
|
|
to_json({ |
96
|
|
|
|
|
|
|
error => $sMsg, |
97
|
|
|
|
|
|
|
result => $oRes, |
98
|
|
|
|
|
|
|
}); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
101
|
|
|
|
|
|
|
# new : mainly for request |
102
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
103
|
|
|
|
|
|
|
sub new($$) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
0
|
1
|
|
my($sClass, $sUrl) = @_; |
106
|
0
|
|
|
|
|
|
my $oUa = LWP::UserAgent->new(); |
107
|
0
|
|
|
|
|
|
$oUa->env_proxy(); |
108
|
|
|
|
|
|
|
return |
109
|
0
|
|
|
|
|
|
bless { |
110
|
|
|
|
|
|
|
URL => $sUrl, |
111
|
|
|
|
|
|
|
_lwpUa => $oUa, |
112
|
|
|
|
|
|
|
}, $sClass; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
# _buildParam : for request |
116
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
117
|
|
|
|
|
|
|
sub _buildParam($%) |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
0
|
|
|
my($oSelf, %hParam) = @_; |
120
|
0
|
|
|
|
|
|
my $sPrm = ''; |
121
|
0
|
0
|
|
|
|
|
if(%hParam) |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
|
|
|
while(my($sKey, $sVal) = each(%hParam)) |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
0
|
|
|
|
|
$sPrm .= '&' if($sPrm ne ''); |
126
|
0
|
0
|
|
|
|
|
$sVal = ($sVal)? URI::Escape::uri_escape_utf8($sVal) : ''; |
127
|
0
|
|
|
|
|
|
$sPrm .= "$sKey=$sVal"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
return $sPrm; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
133
|
|
|
|
|
|
|
# call : |
134
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
135
|
|
|
|
|
|
|
sub call($@) |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
0
|
1
|
|
my($oSelf, @aPrm) = @_; |
138
|
0
|
0
|
|
|
|
|
if(ref($oSelf->{URL}) ne '') |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
|
my $sFunc = shift(@aPrm); |
141
|
0
|
|
|
|
|
|
return $oSelf->{URL}->$sFunc(@aPrm); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
|
my %hPrm; |
146
|
0
|
0
|
|
|
|
|
if(@aPrm) |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
|
|
|
$hPrm{_prm} = to_json(\@aPrm); |
149
|
|
|
|
|
|
|
} |
150
|
0
|
|
|
|
|
|
my $sPrm = $oSelf->_buildParam(%hPrm); |
151
|
0
|
|
|
|
|
|
my $oReq = new HTTP::Request('POST', $oSelf->{URL}); |
152
|
0
|
|
|
|
|
|
$oReq->header('Content-Type', |
153
|
|
|
|
|
|
|
'application/x-www-form-urlencoded; charset=UTF-8'); |
154
|
0
|
|
|
|
|
|
$oReq->header('Accept-Charset', 'UTF-8'); |
155
|
0
|
|
|
|
|
|
$oReq->add_content($sPrm . "\x0d\x0a"); |
156
|
0
|
|
|
|
|
|
my $oRes = $oSelf->{_lwpUa}->request($oReq); |
157
|
0
|
0
|
|
|
|
|
if ($oRes->is_success) |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
|
my $rhRes = from_json($oRes->content); |
160
|
0
|
0
|
|
|
|
|
die($rhRes->{error}) if($rhRes->{error}); |
161
|
0
|
|
|
|
|
|
return $rhRes->{result}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
|
die($oRes->as_string); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
__END__ |