Labyrinth.pm

filter: Statementstmt 48.4% 62 / 128 Branchbran 9.0% 4 / 44 Conditioncond 11.7% 2 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 89.4% 17 / 19 Podpod 100% 4 / 4 totaltotal 40.0% 89 / 222 CC 31 SCAR 55.9
CC
31
Cov
36%
run
464.4
action
20.0
load
2.0
CRAP 267.4
« Labyrinth/Writer.pm ↑ Summary Labyrinth/Media.pm »
1 package Labyrinth;
2  
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '5.32';
7  
8 =head1 NAME
9  
10 Labyrinth - An extensible website in a box.
11  
12 =head1 SYNOPSIS
13  
14 use Labyrinth;
15 my $labyrinth = Labyrinth->new();
16 $labyrinth->run();
17  
18 =head1 DESCRIPTION
19  
20 Documentation overview for Labyrinth.
21  
22 Labyrinth began life in 2002, with a small set of plugins to enable various
23 features of web site management. The core set of plugins are now available as
24 the Labyrinth-Plugin-Core package, with this package providing the core
25 functionality that drives the Labyrinth framework system.
26  
27 See the individual files for more details on how to use them.
28  
29 =cut
30  
31 # -------------------------------------
32 # Library Modules
33  
34 6 ▶use Module::Pluggable search_path => ['Labyrinth::Plugin'];
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # Required Core
37 6 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 6 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 6 ▶use Labyrinth::Globals qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 6 ▶use Labyrinth::Mailer;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 6 ▶use Labyrinth::Plugins;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 6 ▶use Labyrinth::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 6 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 6 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 6 ▶use Labyrinth::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 6 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # -------------------------------------
49 # Variables
50  
51 6 my %plugins;
52  
53 # -------------------------------------
54 # The Program
55  
56 =head1 FUNCTIONS
57  
58 =head2 Constructor
59  
60 =over 4
61  
62 =item new()
63  
64 Instantiates the Labyrinth object.
65  
66 =back
67  
68 =cut
69  
70 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
71 1 my $self = shift;
72  
73 # create an attributes hash
74 1 my $atts = {};
75  
76 # create the object
77 1 bless $atts, $self;
78 1 return $atts;
79 }
80  
81 =head2 Methods
82  
83 =over 4
84  
85 =item run()
86  
87 Provides the dispatch loop, instantiating any configuration required, then
88 processes each command in turn, before finally publishing the result.
89  
90 =cut
91  
92 2 ▶sub run {
Subroutine run: called CC=28 SCAR=61.4
Pod documented
93 2 my ($self,$file,%hash) = @_;
94 2 my ($user,$realm,$command,$request);
95  
96 2 my $LAYOUT = 'public/layout.html';
97 2 my $default_realm = 'public';
98 2 ▶ $default_realm = $hash{realm} if(%hash && $hash{realm});
Branch: 1 branch
BranchTrueFalseTotal
if %hash and $hash{"realm"} 0 2 2
Condition33%1/3
%hash and $hash{"realm"}
!ll&&!rl&&r
200
MC/DC0%0/2
%hash and $hash{"realm"}
%hash $hash{"realm"}
Truth table33%1/3
A and B
A= %hashB= $hash{"realm"}
ABresult
0X0
100
111
99  
100 2 $tvars{errcode} = '';
101  
102 2 eval {
103 2 Labyrinth::Variables::init(); # initial standard variable values
104  
105 2 UnPublish(); # Start a fresh slate
106 2 LoadSettings($file); # Load All Global Settings
107  
108 0 ▶ eval "use Labyrinth::Paths";
Subroutine BEGIN: called CC=1 SCAR=1.7
Subroutine BEGIN: called CC=1 SCAR=1.7
109 2 ▶ unless($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 2 2
110 0 my $paths = Labyrinth::Paths->new();
111 0 $paths->parse();
112 }
113  
114 2 ▶ die $tvars{errmess} if($tvars{errcode} && $tvars{errcode} eq 'ERROR');
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "ERROR" 2 0 2
Condition33%1/3
$Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "ERROR"
!ll&&!rl&&r
002
MC/DC0%0/2
$Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "ERROR"
$Labyrinth::tvars{"errcode"} $Labyrinth::tvars{"errcode"} eq "ERROR"
Truth table33%1/3
A and B
A= $Labyrinth::tvars{"errcode"}B= $Labyrinth::tvars{"errcode"} eq "ERROR"
ABresult
0X0
100
111
115  
116 0 MailSet(mailsend => $settings{mailsend}, logdir => $settings{logdir});
117  
118 0 DBConnect();
119 0 ParseParams();
120  
121 ## defaults in the event of errors
122 0 $tvars{layout} = $LAYOUT;
123 0 $tvars{content} = '';
124  
125 ## session validation & the request
126 0 $user = ValidSession();
127 0 ▶ $realm = $user ? $user->realm : $default_realm;
Branch: 1 branch
BranchTrueFalseTotal
$user ? : 0 0 0
128 0 $command = $cgiparams{act};
129 0 $request = Labyrinth::Request->new($realm,$command);
130 0 $tvars{realm} = $realm;
131  
132 0 $self->load;
133 };
134  
135 2 ▶ die "Cannot start Labyrinth: $@\n" if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 0 2
136  
137 ## 1. each request is only the start.
138 ## 2. upon success or failure it is possible other commands will follow.
139 ## 3. the content for each command can be different.
140 ## 4. if errcode is set, we check if a failure command is required first.
141 ## 5. if no more commands we publish.
142  
143 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$command and do { do { $Labyrinth::tvars{"errcode"} = undef; while (my $action = $request->next_action) { do { LogDebug("run: action=$action"); $self->action($action); if ($Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "NEXT") { $Labyrinth::tvars{"errcode"} = undef; $command = $Labyrinth::tvars{"command"}; while ($request->next_action) { (); } ; $request->reset_request($command) if $command; } ; $realm ||= ""; $Labyrinth::tvars{"realm"} ||= ""; if ($realm ne $Labyrinth::tvars{"realm"}) { $realm = $Labyrinth::tvars{"realm"}; $request->reset_realm($Labyrinth::tvars{"realm"}); } ; last if $Labyrinth::tvars{"errcode"} }; } ; LogDebug('run: 1.errcode=' . ($Labyrinth::tvars{"errcode"} || "undef")); if (not defined $Labyrinth::tvars{"errcode"}) { $command = $request->onsuccess; } elsif ($Labyrinth::tvars{"errcode"} eq "NEXT") { $command = $Labyrinth::tvars{"command"}; } elsif ($Labyrinth::tvars{"errcode"} eq "ERROR") { $command = $request->onerror; } elsif ($Labyrinth::tvars{"errcode"} eq "FAIL") { $command = $request->onfailure; } elsif ($Labyrinth::tvars{"errcode"}) { $command = 'error-' . lc($Labyrinth::tvars{"errcode"}); } else { $command = $request->onsuccess; } ; LogDebug('run: command=' . ($command || "undef")); if ($command) { $request->reset_request($command); } else { $command = undef; } } } 0 0 0
144 0 $tvars{errcode} = undef;
145  
146 0 ▶ while(my $action = $request->next_action) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $request->next_action) 0 0 0
147 0 LogDebug("run: action=$action");
148 0 $self->action($action);
149  
150 0 ▶ if($tvars{errcode} && $tvars{errcode} eq 'NEXT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "NEXT") 0 0 0
Condition0%0/3
$Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "NEXT"
!ll&&!rl&&r
000
MC/DC0%0/2
$Labyrinth::tvars{"errcode"} and $Labyrinth::tvars{"errcode"} eq "NEXT"
$Labyrinth::tvars{"errcode"} $Labyrinth::tvars{"errcode"} eq "NEXT"
Truth table0%0/3
A and B
A= $Labyrinth::tvars{"errcode"}B= $Labyrinth::tvars{"errcode"} eq "NEXT"
ABresult
0X0
100
111
151 0 $tvars{errcode} = undef;
152 0 $command = $tvars{command};
153 0 ▶ while($request->next_action) {} # ignore remaining actions
Branch: 1 branch
BranchTrueFalseTotal
if ($request->next_action) 0 0 0
154 0 ▶ $request->reset_request($command) if($command);
Branch: 1 branch
BranchTrueFalseTotal
if $command 0 0 0
155 #if($tvars{redirect}) {
156 # Publish();
157 # return;
158 #}
159 }
160  
161 0 ▶ $realm ||= '';
Condition0%0/2
$realm ||= ""
l!l
00
MC/DC0%0/1
$realm ||= ""
$realm
Truth table0%0/2
A
A= $realm
Aresult
11
00
162 0 ▶ $tvars{realm} ||= '';
Condition0%0/2
$Labyrinth::tvars{"realm"} ||= ""
l!l
00
MC/DC0%0/1
$Labyrinth::tvars{"realm"} ||= ""
$Labyrinth::tvars{"realm"}
Truth table0%0/2
A
A= $Labyrinth::tvars{"realm"}
Aresult
11
00
163  
164 0 ▶ if($realm ne $tvars{realm} ) { # just in case of a login/logout
Branch: 1 branch
BranchTrueFalseTotal
if ($realm ne $Labyrinth::tvars{"realm"}) 0 0 0
165 0 $realm = $tvars{realm};
166 0 $request->reset_realm($tvars{realm});
167 }
168  
169 0 ▶ last if $tvars{errcode};
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::tvars{"errcode"} 0 0 0
170 }
171  
172 0 ▶LogDebug("run: 1.errcode=".($tvars{errcode} || 'undef'));
Condition0%0/2
$Labyrinth::tvars{'errcode'} || 'undef'
l!l
00
MC/DC0%0/1
$Labyrinth::tvars{'errcode'} || 'undef'
$Labyrinth::tvars{'errcode'}
Truth table0%0/2
A
A= $Labyrinth::tvars{'errcode'}
Aresult
11
00
173  
174 0 ▶ if(!defined $tvars{errcode}) { $command = $request->onsuccess }
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $Labyrinth::tvars{'errcode'}) { } 0 0 0
elsif ($Labyrinth::tvars{'errcode'} eq 'NEXT') { } 0 0 0
elsif ($Labyrinth::tvars{'errcode'} eq 'ERROR') { } 0 0 0
elsif ($Labyrinth::tvars{'errcode'} eq 'FAIL') { } 0 0 0
elsif ($Labyrinth::tvars{'errcode'}) { } 0 0 0
175 0 elsif($tvars{errcode} eq 'NEXT') { $command = $tvars{command} }
176 0 elsif($tvars{errcode} eq 'ERROR') { $command = $request->onerror }
177 0 elsif($tvars{errcode} eq 'FAIL') { $command = $request->onfailure }
178 0 elsif($tvars{errcode}) { $command = 'error-' . lc($tvars{errcode}) }
179 0 else { $command = $request->onsuccess }
180  
181 0 ▶LogDebug("run: command=".($command || 'undef'));
Condition0%0/2
$command || 'undef'
l!l
00
MC/DC0%0/1
$command || 'undef'
$command
Truth table0%0/2
A
A= $command
Aresult
11
00
182  
183 0 ▶ if($command) { $request->reset_request($command) }
Branch: 1 branch
BranchTrueFalseTotal
if ($command) { } 0 0 0
184 0 else { $command = undef }
185  
186 #if($tvars{redirect}) {
187 # Publish();
188 # return;
189 #}
190 } while($command);
191  
192 # just in case some joker has tried to access the realm directly
193 0 $request->reset_realm($tvars{realm});
194  
195 0 foreach my $field (qw(layout content)) {
196 0 my $value = $request->$field();
197 0 ▶ $tvars{$field} = $value if($value);
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
198 }
199 0 LogDebug("run: layout=$tvars{layout}");
200 0 LogDebug("run: content=$tvars{content}");
201 0 LogDebug("run: loggedin=$tvars{loggedin}");
202  
203 0 return Publish();
204 }
205  
206 =item load()
207  
208 Loads plugins found within the plugin directory.
209  
210 =item action($action)
211  
212 Calls the appropriate plugin method.
213  
214 =back
215  
216 =cut
217  
218 0 ▶sub load {
Subroutine load: not called CC=1 SCAR=6.9
Pod documented
219 0 my $self = shift;
220 0 load_plugins($self->plugins());
221 }
222  
223 0 ▶sub action {
Subroutine action: not called CC=4 SCAR=30.0
Pod documented
224 0 my ($self,$action) = @_;
225 0 my ($class,$method) = ($action =~ /(.*)::(.*)/);
226 0 ▶ $class = ($class =~ /^Labyrinth/ ? $class : 'Labyrinth::Plugin::' . $class);
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^Labyrinth/ ? : 0 0 0
227  
228 0 ▶ if(my $plugin = get_plugin($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $plugin = get_plugin($class)) { } 0 0 0
229 0 eval { $plugin->$method(); };
230  
231 # this may fail at the moment, as not all requests have an onerror entry.
232 # as such a default (badcommand?) may need to be set.
233  
234 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
235 0 $tvars{errcode} = 'ERROR';
236 0 LogError("action: class=$class, method=$method, FAULT: $@");
237 }
238 } else {
239 0 $tvars{errcode} = 'MESSAGE';
240 0 LogError("action: class=$class, method=$method, FAULT: class not loaded");
241 }
242 }
243  
244 6 1;
245  
246 __END__
« Labyrinth/Writer.pm ↑ Summary Labyrinth/Media.pm »