blib/lib/CGI/MiniFramework.pm

filter: Statementstmt 13.2% 11 / 83 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 20.0% 2 / 10 Podpod 87.5% 7 / 8 totaltotal 13.3% 20 / 150 CC 23 SCAR 35.4
CC
23
Cov
8%
run
72.0
init
42.0
get_object
30.0
CRAP 34.3
↑ Summary
1 package CGI::MiniFramework;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7 1 our $MODE;
8 1 our $MODULE;
9 1 our $ERROR_MSG;
10  
11 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 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 0 ▶sub get_path_info {
Subroutine get_path_info: not called CC=4 SCAR=30.0
Pod undocumented
23 0 my $self = shift;
24  
25 0 my $path_info = $ENV{'PATH_INFO'};
26  
27 0 ▶ if ( ! $path_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path_info) 0 0 0
28 0 $path_info = '/';
29 }
30  
31 0 ▶ $path_info = "/$path_info" if(index($path_info, '/') != 0);
Branch: 1 branch
BranchTrueFalseTotal
if index($path_info, "/") != 0 0 0 0
32  
33 0 my ($module,$mode) = (split(/\//,$path_info))[1,2];
34  
35 0 ▶ if ( $module ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) { } 0 0 0
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 0 ▶sub init {
Subroutine init: not called CC=6 SCAR=37.4
Pod documented
46 0 my $self = shift;
47 0 my $module = shift;
48 0 my $mode = shift;
49  
50 0 ▶ $self->mode($mode) if $mode;
Branch: 1 branch
BranchTrueFalseTotal
if $mode 0 0 0
51  
52 0 ▶ if ( $mode ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode) { } 0 0 0
elsif ($self->{'DEFAULT_MODE'}) { } 0 0 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 ▶ if ( $module ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module) { } 0 0 0
elsif ($self->{'DEFAULT'}) { } 0 0 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 0 ▶sub run {
Subroutine run: not called CC=8 SCAR=42.8
Pod documented
76 0 my $self = shift;
77  
78 0 my $obj = $self->get_object;
79  
80 0 ▶ if ( ! $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
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 ▶ if ( ! $do_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($do_mode) 0 0 0
89 0 my $class = ref($obj);
90 0 die "There is no execution method in $class .";
91 }
92  
93 0 ▶ $obj->pre_run if $obj->can("pre_run");
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("pre_run") 0 0 0
94  
95 0 my $output;
96 0 eval {
97 0 $output = $obj->$do_mode;
98 };
99  
100 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
101 0 ▶ $obj->error_mode if $obj->can("error_mode");
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("error_mode") 0 0 0
102 0 die "The error occurs by your script.";
103 }
104  
105 0 ▶ if ( ! $output ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output) 0 0 0
106 0 die "Output data doesn't exist.";
107 }
108  
109 0 ▶ $obj->teardown if $obj->can("teardown");
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("teardown") 0 0 0
110  
111 0 return $output;
112 }
113  
114 0 ▶sub get_object {
Subroutine get_object: not called CC=5 SCAR=34.0
Pod documented
115 0 my $self = shift;
116 0 my $module = $self->module;
117  
118 0 ▶ if ( $self->{'PREFIX'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PREFIX"}) 0 0 0
119 0 $module = $self->{'PREFIX'}.'::'.$module;
120 }
121  
122 0 ▶ eval "require $module"
Branch: 1 branch
BranchTrueFalseTotal
eval "require $module" or $self->error($!) and return undef 0 0 0
Condition0%0/5
eval "require $module" || $self->error($!) && (return undef)
l!l&&r!l&&!r
000
$self->error($!) and return undef
!ll
00
MC/DC0%0/2
eval "require $module" || $self->error($!) && (return undef)
eval "require $module" $self->error($!)
Truth table0%0/3
A || B
A= eval "require $module"B= $self->error($!)
ABresult
1X1
011
000
123 or $self->error($!) and return undef;
124  
125 0 my $obj;
126 0 eval {
127 0 $obj = $module->new;
128 };
129 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
130 0 $self->error($@);
131 0 return undef;
132 }
133  
134 0 return $obj;
135 }
136  
137 0 ▶sub module {
Subroutine module: not called CC=2 SCAR=17.9
Pod documented
138 0 my $self = shift;
139 0 ▶ if(@_) { $MODULE = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
140 0 return $MODULE;
141 }
142  
143 0 ▶sub mode {
Subroutine mode: not called CC=2 SCAR=17.9
Pod documented
144 0 my $self = shift;
145 0 ▶ if(@_) { $MODE = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
146 0 return $MODE;
147 }
148  
149 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
150 0 my $self = shift;
151 0 ▶ if(@_) { $ERROR_MSG = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
152 0 return $ERROR_MSG;
153 }
154  
155 1 1;
156 __END__
↑ Summary