line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::MiniFramework; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25455
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
821
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
our $MODE; |
8
|
|
|
|
|
|
|
our $MODULE; |
9
|
|
|
|
|
|
|
our $ERROR_MSG; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my($class,$self)=(shift,{@_}); |
13
|
0
|
|
|
|
|
|
bless($self,$class); |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my ($module,$mode) = $self->get_path_info; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
$self->init($module,$mode); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub get_path_info { |
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $path_info = $ENV{'PATH_INFO'}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if ( ! $path_info ) { |
28
|
0
|
|
|
|
|
|
$path_info = '/'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
$path_info = "/$path_info" if(index($path_info, '/') != 0); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my ($module,$mode) = (split(/\//,$path_info))[1,2]; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ( $module ) { |
36
|
0
|
|
|
|
|
|
($module) = ($module =~ /^([A-Za-z][A-Za-z0-9_\-\:\']+)$/); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
|
|
|
|
|
$mode = q{}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return ($module,$mode); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub init { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my $module = shift; |
48
|
0
|
|
|
|
|
|
my $mode = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
$self->mode($mode) if $mode; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ( $mode ) { |
|
|
0
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->mode($mode); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif( $self->{'DEFAULT_MODE'} ) { |
56
|
0
|
|
|
|
|
|
$self->mode($self->{'DEFAULT_MODE'}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
0
|
|
|
|
|
|
$self->mode('start'); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( $module ) { |
|
|
0
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->module($module); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif( $self->{'DEFAULT'} ) { |
66
|
0
|
|
|
|
|
|
$self->module($self->{'DEFAULT'}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
0
|
|
|
|
|
|
$self->module(q{}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub run { |
76
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $obj = $self->get_object; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ( ! $obj ) { |
81
|
0
|
|
|
|
|
|
die $self->error; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $mode = $self->mode; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $do_mode = $obj->setup($mode); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ( ! $do_mode ) { |
89
|
0
|
|
|
|
|
|
my $class = ref($obj); |
90
|
0
|
|
|
|
|
|
die "There is no execution method in $class ."; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
$obj->pre_run if $obj->can("pre_run"); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $output; |
96
|
0
|
|
|
|
|
|
eval { |
97
|
0
|
|
|
|
|
|
$output = $obj->$do_mode; |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
101
|
0
|
0
|
|
|
|
|
$obj->error_mode if $obj->can("error_mode"); |
102
|
0
|
|
|
|
|
|
die "The error occurs by your script."; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ( ! $output ) { |
106
|
0
|
|
|
|
|
|
die "Output data doesn't exist."; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
$obj->teardown if $obj->can("teardown"); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $output; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_object { |
115
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
116
|
0
|
|
|
|
|
|
my $module = $self->module; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( $self->{'PREFIX'} ) { |
119
|
0
|
|
|
|
|
|
$module = $self->{'PREFIX'}.'::'.$module; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
0
|
|
|
|
eval "require $module" |
123
|
|
|
|
|
|
|
or $self->error($!) and return undef; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $obj; |
126
|
0
|
|
|
|
|
|
eval { |
127
|
0
|
|
|
|
|
|
$obj = $module->new; |
128
|
|
|
|
|
|
|
}; |
129
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
130
|
0
|
|
|
|
|
|
$self->error($@); |
131
|
0
|
|
|
|
|
|
return undef; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return $obj; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub module { |
138
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
139
|
0
|
0
|
|
|
|
|
if(@_) { $MODULE = shift } |
|
0
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $MODULE; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub mode { |
144
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
145
|
0
|
0
|
|
|
|
|
if(@_) { $MODE = shift } |
|
0
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return $MODE; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub error { |
150
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
151
|
0
|
0
|
|
|
|
|
if(@_) { $ERROR_MSG = shift } |
|
0
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $ERROR_MSG; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
__END__ |