OpenInteract2/Context.pm

filter: Statementstmt 31.3% 122 / 389 Branchbran 14.4% 20 / 138 Conditioncond 12.6% 11 / 87 MC/DCmcdc 0.0% 0 / 56 Subroutinesub 24.6% 18 / 73 Podpod 1.6% 1 / 62 totaltotal 21.3% 172 / 805 CC 104 SCAR 31.6
CC
104
Cov
25%
lookup_action_info
90.0
action_table
90.0
check_security
56.0
CRAP 23.7
« OpenInteract2/Log/OIAppender.pm ↑ Summary OpenInteract2/Manage/Website/CleanOrphanedUsers.pm »
1 package OpenInteract2::Context;
2  
3 # $Id: Context.pm,v 1.87 2005/03/17 14:57:57 sjn Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( Exporter Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 87 ▶use OpenInteract2::Log qw( uchk );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 87 $OpenInteract2::Context::VERSION = sprintf("%d.%02d", q$Revision: 1.87 $ =~ /(\d+)\.(\d+)/);
14  
15 87 ▶use constant DEFAULT_TEMP_LIB_DIR => 'templib';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 87 my ( $log_spops, $log_act, $log_init );
18  
19 0 ▶sub version { return '1.99_06' }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
20  
21 # Exportable deployment URL call -- main, images, static
22  
23 87 my ( $DEPLOY_URL, $DEPLOY_IMAGE_URL, $DEPLOY_STATIC_URL );
24 0 ▶sub DEPLOY_URL { return $DEPLOY_URL }
Subroutine DEPLOY_URL: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub DEPLOY_IMAGE_URL { return $DEPLOY_IMAGE_URL }
Subroutine DEPLOY_IMAGE_URL: not called CC=1 SCAR=6.9
Pod undocumented
26 0 ▶sub DEPLOY_STATIC_URL { return $DEPLOY_STATIC_URL }
Subroutine DEPLOY_STATIC_URL: not called CC=1 SCAR=6.9
Pod undocumented
27  
28 87 my ( $DEFAULT_LANGUAGE_HANDLE );
29  
30 # This is the only copy of the context that should be around. We might
31 # modify this later so we can have multiple copies of the context
32 # around (produced by, say, a ContextFactory), but W(P)AGNI. Note that
33 # before accessing the exported variable you should first ensure that
34 # it's initialized.
35  
36 87 my ( $CTX );
37 18 ▶sub CTX { return $CTX }
Subroutine CTX: called CC=1 SCAR=0.0
Pod undocumented
38  
39 87 @OpenInteract2::Context::EXPORT_OK = qw(
40 CTX DEPLOY_URL DEPLOY_IMAGE_URL DEPLOY_STATIC_URL
41 );
42  
43 87 require OpenInteract2::Config;
44 87 require OpenInteract2::Config::Bootstrap;
45 87 require OpenInteract2::DatasourceManager;
46 87 require OpenInteract2::Observer;
47 87 require OpenInteract2::Request;
48 87 require OpenInteract2::Response;
49 87 require OpenInteract2::Action;
50 87 require OpenInteract2::Controller;
51 87 require OpenInteract2::Exception;
52 87 require OpenInteract2::Setup;
53 87 require OpenInteract2::I18N;
54  
55 87 my @CORE_FIELDS = qw( bootstrap repository packages cache
56 datasource_manager timezone timezone_object setup_class );
57 87 my @REQUEST_FIELDS = qw( request response controller user group is_logged_in is_admin );
58 87 __PACKAGE__->mk_accessors( @CORE_FIELDS, @REQUEST_FIELDS );
59  
60 ########################################
61 # CONSTRUCTOR AND INITIALIZATION
62  
63 # $item should be either a hashref of parameters (preferably with one
64 # parameter 'website_dir') or an OI2::Config::Bootstrap object
65  
66 1 ▶sub create {
Subroutine create: called CC=15 SCAR=36.0
Pod undocumented
67 1 my ( $class, $item, $params ) = @_;
68 1 ▶ return $CTX if ( $CTX );
Branch: 1 branch
BranchTrueFalseTotal
if $CTX 0 1 1
69 1 ▶ $item ||= {};
Condition50%1/2
$item ||= {}
l!l
10
MC/DC0%0/1
$item ||= {}
$item
Truth table50%1/2
A
A= $item
Aresult
11
00
70 1 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
10
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
71  
72 1 my ( $website_dir );
73  
74 # Don't assign this to $CTX until after it's setup!
75 1 my $ctx = bless( {}, $class );
76  
77 1 my ( $bootstrap );
78 1 ▶ if ( ref $item eq 'OpenInteract2::Config::Bootstrap' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'OpenInteract2::Config::Bootstrap') { } 1 0 1
elsif ($item->{'website_dir'}) { } 0 0 0
79 1 $bootstrap = $item;
80 1 $website_dir = $bootstrap->website_dir;
81 }
82 elsif ( $item->{website_dir} ) {
83 0 $bootstrap = eval {
84 OpenInteract2::Config::Bootstrap->new({
85 website_dir => $item->{website_dir}
86 })
87 0 };
88 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
89 0 OpenInteract2::Exception->throw(
90 "Cannot create bootstrap object using website ",
91 "directory '$item->{website_dir}': $@" );
92 }
93 0 $website_dir = $item->{website_dir};
94 }
95  
96 # this is typically only set from standalone scripts; see POD
97  
98 1 ▶ if ( $params->{initialize_log} and -d $website_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'initialize_log'} and -d $website_dir) { } 0 1 1
elsif ($params->{'initialize_log'}) { } 0 1 1
Condition33%1/3
$params->{"initialize_log"} and -d $website_dir
!ll&&!rl&&r
100
MC/DC0%0/2
$params->{"initialize_log"} and -d $website_dir
$params->{"initialize_log"} -d $website_dir
Truth table33%1/3
A and B
A= $params->{"initialize_log"}B= -d $website_dir
ABresult
0X0
100
111
99 0 OpenInteract2::Log->init_from_website( $website_dir );
100 }
101 elsif ( $params->{initialize_log} ) {
102 0 OpenInteract2::Log->init_screen;
103 }
104  
105 1 ▶ $log_init ||= get_logger( LOG_INIT );
Condition33%1/3
$log_init ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
010
MC/DC0%0/2
$log_init ||= get_logger("OI2.INITIALIZE")
$log_init get_logger("OI2.INITIALIZE")
Truth table33%1/3
A ||= B
A= $log_initB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
106  
107 1 ▶ if ( $bootstrap ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bootstrap) 1 0 1
108 1 $ctx->bootstrap( $bootstrap );
109 1 ▶ $log_init->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_debug and $log_init->debug("Assigned bootstrap ok; setting up...") 0 1 1
110 $log_init->debug( "Assigned bootstrap ok; setting up..." );
111 1 eval { $ctx->setup( $params ) };
112 1 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 1 0 1
113 1 my $error = $@;
114 1 $CTX = undef;
115 1 $log_init->error( "Setup failed to run: $error" );
116 1 OpenInteract2::Exception->throw( $error );
117 }
118 else {
119 0 ▶ $log_init->is_info && $log_init->info( "Setup ran ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Setup ran ok") 0 0 0
120 }
121 }
122 0 return $CTX = $ctx
123 }
124  
125  
126 3 ▶sub instance {
Subroutine instance: called CC=3 SCAR=11.0
Pod undocumented
127 3 my ( $class, $no_exception ) = @_;
128 3 ▶ return $CTX if ( $CTX );
Branch: 1 branch
BranchTrueFalseTotal
if $CTX 0 3 3
129 3 ▶ if ( $no_exception ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_exception) 2 1 3
130 2 return undef;
131 }
132 OpenInteract2::Exception->throw(
133 1 "No context available; first call 'create()'" );
134 }
135  
136  
137 # Initialize the Context
138  
139 1 ▶sub setup {
Subroutine setup: called CC=6 SCAR=21.8
Pod undocumented
140 1 my ( $self, $params ) = @_;
141 1 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
10
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
142  
143 1 my @skip = ();
144 1 ▶ if ( $params->{skip} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"skip"}) 1 0 1
145 1 ▶ if ( ref $params->{skip} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params->{'skip'} eq 'ARRAY') { } 0 1 1
146 0 push @skip, @{ $params->{skip} };
147 }
148 else {
149 1 push @skip, $params->{skip};
150 }
151 1 $log_init->info( "Will skip setup tasks: ", join( ', ', @skip ) );
152 }
153 1 my $bootstrap = $self->bootstrap;
154 1 ▶ unless ( $bootstrap and
Branch: 1 branch
BranchTrueFalseTotal
unless ($bootstrap and ref $bootstrap eq "OpenInteract2::Config::Bootstrap") 0 1 1
Condition33%1/3
$bootstrap and ref $bootstrap eq "OpenInteract2::Config::Bootstrap"
!ll&&!rl&&r
001
MC/DC0%0/2
$bootstrap and ref $bootstrap eq "OpenInteract2::Config::Bootstrap"
$bootstrap ref $bootstrap eq "OpenInteract2::Config::Bootstrap"
Truth table33%1/3
A and B
A= $bootstrapB= ref $bootstrap eq "OpenInteract2::Config::Bootstrap"
ABresult
0X0
100
111
155 ref( $bootstrap ) eq 'OpenInteract2::Config::Bootstrap' ) {
156 0 $log_init->error( "Cannot run setup() without bootstrap defined" );
157 0 OpenInteract2::Exception->throw(
158 "Cannot run setup() on context without a valid ",
159 "bootstrap configuration object set" );
160 }
161  
162 # This should call _initialize_singleton() when it's got the
163 # context in a decent state...
164  
165 1 $log_init->info( "Running setup actions..." );
166 1 OpenInteract2::Setup->run_all_actions( $self, @skip );
167 0 $log_init->info( "Setup actions ran ok, context now initialized" );
168  
169 0 return $self;
170 }
171  
172  
173 # Called from OI2::Setup after it's read the server configuration
174 1 ▶sub _initialize_singleton {
Subroutine _initialize_singleton: called CC=1 SCAR=0.0
175 1 my ( $self ) = @_;
176 1 $CTX = $self;
177 }
178  
179  
180 ########################################
181 # CONFIGURATION ASSIGNMENTS
182 #
183 # These subroutines generally map to some basic system information
184 # that can be modified at runtime in addition to the modifications in
185 # the configuration. Note: modifications made here should get
186 # reflected in the configuration as well.
187  
188 7 ▶sub server_config {
Subroutine server_config: called CC=3 SCAR=11.0
Pod undocumented
189 7 my ( $self, $config ) = @_;
190 7 ▶ if ( $config ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 1 6 7
191 1 ▶ $log_init ||= get_logger( LOG_INIT );
Condition33%1/3
$log_init ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
100
MC/DC0%0/2
$log_init ||= get_logger("OI2.INITIALIZE")
$log_init get_logger("OI2.INITIALIZE")
Truth table33%1/3
A ||= B
A= $log_initB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
192 1 $config->{dir}{website} = $self->bootstrap->website_dir;
193 1 $config->translate_dirs;
194 1 $log_init->info( "Translated server config directories ok" );
195  
196 1 $self->{server_config} = $config;
197 1 $self->assign_deploy_url;
198 1 $self->assign_deploy_image_url;
199 1 $self->assign_deploy_static_url;
200 1 $log_init->info( "Assigned constants from server config ok" );
201 }
202 7 return $self->{server_config};
203 }
204  
205 # Where is this app deployed under?
206  
207 1 ▶sub assign_deploy_url {
Subroutine assign_deploy_url: called CC=5 SCAR=18.3
Pod undocumented
208 1 my ( $self, $url ) = @_;
209  
210 1 ▶ $url ||= $self->server_config->{context_info}{deployed_under};
Condition33%1/3
$url ||= $self->server_config->{"context_info"}{"deployed_under"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$url ||= $self->server_config->{"context_info"}{"deployed_under"}
$url $self->server_config->{"context_info"}{"deployed_under"}
Truth table33%1/3
A ||= B
A= $urlB= $self->server_config->{"context_info"}{"deployed_under"}
ABresult
1X1
011
000
211 1 $url = $self->_clean_deploy_url( $url );
212 1 ▶ if ( $url and $url !~ m|^/| ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url and not $url =~ m[^/]) 0 1 1
Condition33%1/3
$url and not $url =~ m[^/]
!ll&&!rl&&r
100
MC/DC0%0/2
$url and not $url =~ m[^/]
$url not $url =~ m[^/]
Truth table33%1/3
A and not(B)
A= $urlB= not $url =~ m[^/]
ABresult
0X0
100
111
213 0 OpenInteract2::Exception->throw(
214 "Deployment URL must begin with a '/'. It may not ",
215 "be a fully-qualified URL (e.g., 'http://foo.com/') ",
216 "and it may not be a purely relative URL (e.g., 'oi')" );
217 }
218 1 $DEPLOY_URL = $url;
219 1 $self->server_config->{context_info}{deployed_under} = $url;
220 1 ▶ $log_init->is_info && $log_init->info( "Assigned deployment URL '$url'" );
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Assigned deployment URL '${url}'") 0 1 1
221 1 return $DEPLOY_URL;
222 }
223  
224 1 ▶sub assign_deploy_image_url {
Subroutine assign_deploy_image_url: called CC=3 SCAR=11.4
Pod undocumented
225 1 my ( $self, $url ) = @_;
226  
227 1 ▶ $url ||= $self->server_config->{context_info}{deployed_under_image};
Condition33%1/3
$url ||= $self->server_config->{"context_info"}{"deployed_under_image"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$url ||= $self->server_config->{"context_info"}{"deployed_under_image"}
$url $self->server_config->{"context_info"}{"deployed_under_image"}
Truth table33%1/3
A ||= B
A= $urlB= $self->server_config->{"context_info"}{"deployed_under_image"}
ABresult
1X1
011
000
228 1 $url = $self->_clean_deploy_url( $url );
229 1 $DEPLOY_IMAGE_URL = $url;
230 1 $self->server_config->{context_info}{deployed_under_image} = $url;
231 1 ▶ $log_init->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Assigned image deployment URL '${url}'") 0 1 1
232 $log_init->info( "Assigned image deployment URL '$url'" );
233 1 return $DEPLOY_IMAGE_URL;
234 }
235  
236 1 ▶sub assign_deploy_static_url {
Subroutine assign_deploy_static_url: called CC=3 SCAR=11.4
Pod undocumented
237 1 my ( $self, $url ) = @_;
238  
239 1 ▶ $url ||= $self->server_config->{context_info}{deployed_under_static};
Condition33%1/3
$url ||= $self->server_config->{"context_info"}{"deployed_under_static"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$url ||= $self->server_config->{"context_info"}{"deployed_under_static"}
$url $self->server_config->{"context_info"}{"deployed_under_static"}
Truth table33%1/3
A ||= B
A= $urlB= $self->server_config->{"context_info"}{"deployed_under_static"}
ABresult
1X1
011
000
240 1 $url = $self->_clean_deploy_url( $url );
241 1 $DEPLOY_STATIC_URL = $url;
242 1 $self->server_config->{context_info}{deployed_under_static} = $url;
243 1 ▶ $log_init->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Assigned static deployment URL '${url}'") 0 1 1
244 $log_init->info( "Assigned static deployment URL '$url'" );
245 1 return $DEPLOY_STATIC_URL;
246 }
247  
248 3 ▶sub _clean_deploy_url {
Subroutine _clean_deploy_url: called CC=2 SCAR=10.9
249 3 my ( $self, $url ) = @_;
250 3 ▶ return '' unless ( $url );
Branch: 1 branch
BranchTrueFalseTotal
unless $url 3 0 3
251 0 $url =~ s/^\s+//;
252 0 $url =~ s/\s+$//;
253 0 $url =~ s|/$||;
254 0 return $url;
255 }
256  
257 # What type of requests/responses are we getting/generating?
258  
259  
260 # TODO: get rid of 'context_info' reference; these are strictly
261 # assigned by adapter now
262  
263 0 ▶sub assign_request_type {
Subroutine assign_request_type: not called CC=3 SCAR=24.8
Pod undocumented
264 0 my ( $self, $type ) = @_;
265  
266 0 ▶ $type ||= $self->server_config->{context_info}{request};
Condition0%0/3
$type ||= $self->server_config->{"context_info"}{"request"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= $self->server_config->{"context_info"}{"request"}
$type $self->server_config->{"context_info"}{"request"}
Truth table0%0/3
A ||= B
A= $typeB= $self->server_config->{"context_info"}{"request"}
ABresult
1X1
011
000
267 0 $self->server_config->{context_info}{request} = $type;
268 0 OpenInteract2::Request->set_implementation_type( $type );
269 0 ▶ $log_init->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Assigned request type '${type}'") 0 0 0
270 $log_init->info( "Assigned request type '$type'" );
271 }
272  
273  
274 0 ▶sub assign_response_type {
Subroutine assign_response_type: not called CC=3 SCAR=24.8
Pod undocumented
275 0 my ( $self, $type ) = @_;
276  
277 0 ▶ $type ||= $self->server_config->{context_info}{response};
Condition0%0/3
$type ||= $self->server_config->{"context_info"}{"response"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= $self->server_config->{"context_info"}{"response"}
$type $self->server_config->{"context_info"}{"response"}
Truth table0%0/3
A ||= B
A= $typeB= $self->server_config->{"context_info"}{"response"}
ABresult
1X1
011
000
278 0 $self->server_config->{context_info}{response} = $type;
279 0 OpenInteract2::Response->set_implementation_type( $type );
280 0 ▶ $log_init->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_init->is_info and $log_init->info("Assigned response type '${type}'") 0 0 0
281 $log_init->info( "Assigned response type '$type'" );
282 }
283  
284  
285 ########################################
286 # DATE FACTORY
287  
288 0 ▶sub create_date {
Subroutine create_date: not called CC=5 SCAR=34.0
Pod undocumented
289 0 my ( $self, $params ) = @_;
290 0 ▶ $params ||= {};
Condition0%0/2
$params ||= {}
l!l
00
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
Aresult
11
00
291 0 ▶ if ( $params->{epoch} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($params->{'epoch'}) { } 0 0 0
elsif ($params->{'last_day_of_month'}) { } 0 0 0
elsif ($params->{'year'}) { } 0 0 0
292 return DateTime->from_epoch(
293 time_zone => $self->timezone_object,
294 epoch => $params->{epoch},
295 0 );
296 }
297 elsif ( $params->{last_day_of_month} ) {
298 0 delete $params->{last_day_of_month};
299 return DateTime->last_day_of_month(
300 time_zone => $self->timezone_object,
301 0 %{ $params },
302 );
303 }
304 elsif ( $params->{year} ) {
305 return DateTime->new(
306 time_zone => $self->timezone_object,
307 0 %{ $params }
308 );
309 }
310 else {
311 0 return DateTime->now(
312 time_zone => $self->timezone_object
313 );
314 }
315 }
316  
317  
318 ########################################
319 # ACTION LOOKUP
320  
321 0 ▶sub lookup_action_name {
Subroutine lookup_action_name: not called CC=6 SCAR=37.4
Pod undocumented
322 0 my ( $self, $action_url ) = @_;
323 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
324 0 ▶ unless ( $action_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_url) 0 0 0
325 0 OpenInteract2::Exception->throw(
326 "Cannot lookup action without action name without URL" );
327 }
328 $log_act->is_debug &&
329 0 ▶ $log_act->debug( "Try to find action name for URL '$action_url'" );
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Try to find action name for URL '${action_url}'") 0 0 0
330 0 my $server_config = $self->server_config;
331 0 ▶ my $action_name = $server_config->{action_url}{ $action_url } || '';
Condition0%0/2
$server_config->{'action_url'}{$action_url} || ''
l!l
00
MC/DC0%0/1
$server_config->{'action_url'}{$action_url} || ''
$server_config->{'action_url'}{$action_url}
Truth table0%0/2
A
A= $server_config->{'action_url'}{$action_url}
Aresult
11
00
332 0 ▶ $log_act->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Found name '${action_name}' for URL '${action_url}'") 0 0 0
333 $log_act->debug( "Found name '$action_name' for URL '$action_url'" );
334 0 return $action_name;
335 }
336  
337  
338 0 ▶sub lookup_action_info {
Subroutine lookup_action_info: not called CC=9 SCAR=45.0
Pod undocumented
339 0 my ( $self, $action_name ) = @_;
340 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
341 0 ▶ unless ( $action_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_name) 0 0 0
342 0 $log_act->error( "No action name given to lookup info; called ",
343 "from: ", join( ' | ', caller ) );
344 0 OpenInteract2::Exception->throw(
345 "Cannot lookup action without action name" );
346 }
347  
348 $log_act->is_debug &&
349 0 ▶ $log_act->debug( "Try to find action info for '$action_name'" );
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Try to find action info for '${action_name}'") 0 0 0
350 0 my $server_config = $self->server_config;
351 0 my $action_info = $server_config->{action}{ lc $action_name };
352  
353 # Let the caller deal with a not found action rather than assuming
354 # we know best.
355  
356 0 ▶ unless ( $action_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_info) 0 0 0
357 0 my $msg = "Action '$action_name' not found in action table" ;
358 0 $log_act->error( $msg );
359 0 OpenInteract2::Exception->throw( $msg );
360 }
361  
362 $log_act->is_debug &&
363 $log_act->debug( uchk( "Action '%s' is [Class: %s] [Template: %s] ",
364 $action_name, $action_info->{class},
365 0 ▶ $action_info->{template} ) );
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug(uchk("Action '%s' is [Class: %s] [Template: %s] ", $action_name, $action_info->{"class"}, $action_info->{"template"})) 0 0 0
366  
367 # Allow as many redirects as we need
368  
369 0 my $current_name = $action_name;
370 0 ▶ while ( my $action_redir = $action_info->{redir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action_redir = $action_info->{"redir"}) 0 0 0
371 0 $action_info = $server_config->{action}{ lc $action_redir };
372 0 ▶ unless ( $action_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_info) 0 0 0
373 0 $log_act->warn( "Failed redirect from '$current_name' to ",
374 "'$action_redir': no action defined " );
375 0 return undef;
376 }
377 $log_act->is_debug &&
378 0 ▶ $log_act->debug( "Redirect to '$action_redir'" );
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Redirect to '${action_redir}'") 0 0 0
379 0 $current_name = $action_redir;
380 }
381 0 return $action_info;
382 }
383  
384  
385 0 ▶sub lookup_action {
Subroutine lookup_action: not called CC=3 SCAR=24.8
Pod undocumented
386 0 my ( $self, $action_name, $props ) = @_;
387 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
388 0 my $action_info = $self->lookup_action_info( $action_name );
389 0 ▶ unless ( $action_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_info) 0 0 0
390 0 my $msg = "No action found for '$action_name'";
391 0 $log_act->error( $msg );
392 0 OpenInteract2::Exception->throw( $msg );
393 }
394 0 return OpenInteract2::Action->new( $action_info, $props );
395 }
396  
397 0 ▶sub lookup_action_none {
Subroutine lookup_action_none: not called CC=1 SCAR=6.9
Pod undocumented
398 0 my ( $self ) = @_;
399 0 my $action_name = $self->server_config->{action_info}{none};
400 0 return $self->_create_action_from_name(
401 $action_name, 'action_info.none'
402 );
403 }
404  
405 0 ▶sub lookup_action_not_found {
Subroutine lookup_action_not_found: not called CC=1 SCAR=6.9
Pod undocumented
406 0 my ( $self ) = @_;
407 0 my $action_name = $self->server_config->{action_info}{not_found};
408 0 return $self->_create_action_from_name(
409 $action_name, 'action_info.not_found'
410 );
411 }
412  
413 0 ▶sub _create_action_from_name {
Subroutine _create_action_from_name: not called CC=3 SCAR=24.8
414 0 my ( $self, $name, $key ) = @_;
415 0 ▶ unless ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 0 0
416 0 my $msg = join( '',
417 "Check your server configuration -- you must define an ",
418 "action number in your server configuration under '$key'"
419 );
420 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
421 0 $log_act->error( $msg );
422 0 OpenInteract2::Exception->throw( $msg );
423 }
424 0 return $self->lookup_action( $name );
425 }
426  
427 0 ▶sub lookup_default_action_info {
Subroutine lookup_default_action_info: not called CC=1 SCAR=6.9
Pod undocumented
428 0 my ( $self ) = @_;
429 0 return $self->server_config->{action_info}{default};
430 }
431  
432  
433 ########################################
434 # OBJECT CLASS LOOKUP
435  
436 0 ▶sub lookup_object {
Subroutine lookup_object: not called CC=6 SCAR=37.4
Pod undocumented
437 0 my ( $self, $object_name ) = @_;
438 0 ▶ $log_spops ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log_spops ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_spops ||= get_logger("OI2.SPOPS")
$log_spops get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $log_spopsB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
439 0 ▶ unless ( $object_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object_name) 0 0 0
440 0 my $msg = "Cannot lookup object class without object name";
441 0 $log_spops->error( $msg );
442 0 OpenInteract2::Exception->throw( $msg );
443 }
444 0 my $spops_config = $self->spops_config;
445 0 ▶ unless ( $spops_config->{ lc $object_name } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$spops_config{lc $object_name}) 0 0 0
446 0 my $msg = "No object class found for '$object_name'";
447 0 $log_spops->error( $msg );
448 0 OpenInteract2::Exception->throw( $msg );
449 }
450 0 my $use_name = lc $object_name;
451  
452 # 'alias_class' is defined in the common case when we want to
453 # generate the persistence class ('class') and then subclass it
454 # for our customizations ('alias_class')
455  
456 my $object_class = $spops_config->{ $use_name }{alias_class}
457 0 ▶ || $spops_config->{ $use_name }{class};
Condition0%0/3
$spops_config->{$use_name}{'alias_class'} || $spops_config->{$use_name}{'class'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$spops_config->{$use_name}{'alias_class'} || $spops_config->{$use_name}{'class'}
$spops_config->{$use_name}{'alias_class'} $spops_config->{$use_name}{'class'}
Truth table0%0/3
A || B
A= $spops_config->{$use_name}{'alias_class'}B= $spops_config->{$use_name}{'class'}
ABresult
1X1
011
000
458 0 ▶ $log_spops->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log_spops->is_debug and $log_spops->debug("Found class '${object_class}' for '${object_name}'") 0 0 0
459 $log_spops->debug( "Found class '$object_class' for '$object_name'" );
460 0 return $object_class;
461 }
462  
463  
464 ########################################
465 # CONTROLLER LOOKUP
466  
467 0 ▶sub lookup_controller_config {
Subroutine lookup_controller_config: not called CC=2 SCAR=17.9
Pod undocumented
468 0 my ( $self, $name ) = @_;
469 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
470 0 return $self->server_config->{controller}{ $name };
471 }
472 0 return $self->server_config->{controller};
473 }
474  
475  
476 ########################################
477 # FULLTEXT INDEXING LOOKUP
478  
479 0 ▶sub lookup_fulltext_config {
Subroutine lookup_fulltext_config: not called CC=2 SCAR=17.9
Pod undocumented
480 0 my ( $self, $name ) = @_;
481 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
482 0 return $self->server_config->{fulltext}{ $name };
483 }
484 0 return $self->server_config->{fulltext};
485 }
486  
487 0 ▶sub fulltext_indexer {
Subroutine fulltext_indexer: not called CC=6 SCAR=37.4
Pod undocumented
488 0 my ( $self, $indexer_name ) = @_;
489 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
490  
491 0 my $all_config = $self->lookup_fulltext_config;
492 0 ▶ unless ( $indexer_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($indexer_name) 0 0 0
493 0 $indexer_name = $all_config->{default};
494 0 ▶ unless ( $indexer_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($indexer_name) 0 0 0
495 0 OpenInteract2::Exception->throw(
496 "No fulltext indexer defined in server configuration ",
497 "key 'fulltext.default'" );
498 }
499 }
500  
501 $log_act->is_debug &&
502 0 ▶ $log_act->debug( "Fulltext indexer configured: $indexer_name" );
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Fulltext indexer configured: $indexer_name") 0 0 0
503 0 my $ft_config = $all_config->{ $indexer_name };
504 0 ▶ unless ( ref $ft_config eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ft_config eq "HASH") 0 0 0
505 0 OpenInteract2::Exception->throw(
506 "Fulltext indexer '$indexer_name' set in server ",
507 "configuration key 'fulltext.default' does not ",
508 "have corresponding configuration section." );
509 }
510  
511 0 my $ft_class = $ft_config->{class};
512 0 return $ft_class->new( $ft_config );
513 }
514  
515  
516 ########################################
517 # CONTENT GENERATOR LOOKUP
518  
519 0 ▶sub lookup_content_generator_config {
Subroutine lookup_content_generator_config: not called CC=2 SCAR=17.9
Pod undocumented
520 0 my ( $self, $name ) = @_;
521 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
522 0 return $self->server_config->{content_generator}{ $name };
523 }
524 0 return $self->server_config->{content_generator};
525 }
526  
527  
528 ########################################
529 # OBSERVERS
530  
531 0 ▶sub lookup_observer {
Subroutine lookup_observer: not called CC=2 SCAR=17.9
Pod undocumented
532 0 my ( $self, $name ) = @_;
533 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
534 0 return $self->{observers}{ $name };
535 }
536 0 return $self->{observers};
537 }
538  
539 0 ▶sub set_observer_registry {
Subroutine set_observer_registry: not called CC=1 SCAR=6.9
Pod undocumented
540 0 my ( $self, $registry ) = @_;
541 0 $self->{observers} = $registry;
542 0 return;
543 }
544  
545 0 ▶sub add_observer {
Subroutine add_observer: not called CC=1 SCAR=6.9
Pod undocumented
546 0 my ( $self, $observer_name, $observer_info ) = @_;
547 OpenInteract2::Observer->register_observer(
548 0 $observer_name, $observer_info, $self->{observers} );
549 }
550  
551 0 ▶sub map_observer {
Subroutine map_observer: not called CC=1 SCAR=6.9
Pod undocumented
552 0 my ( $self, $observer_name, $action_or_name ) = @_;
553 0 OpenInteract2::Observer->add_observer_to_action( $observer_name, $action_or_name );
554 }
555  
556  
557 ########################################
558 # DIRECTORY/FILE LOOKUPS
559  
560 0 ▶sub lookup_directory {
Subroutine lookup_directory: not called CC=2 SCAR=17.9
Pod undocumented
561 0 my ( $self, $dir_name ) = @_;
562 0 ▶ if ( $dir_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir_name) 0 0 0
563 0 return $self->server_config->{dir}{ $dir_name };
564 }
565 0 return $self->server_config->{dir};
566 }
567  
568 # TODO: What happens if someone specifies a fully-qualified directory?
569  
570 0 ▶sub lookup_temp_lib_directory {
Subroutine lookup_temp_lib_directory: not called CC=2 SCAR=17.9
Pod undocumented
571 0 my ( $self ) = @_;
572 0 my $bootstrap = $self->bootstrap;
573 0 ▶ my $lib_dir = $bootstrap->temp_lib_dir || DEFAULT_TEMP_LIB_DIR;
Condition0%0/2
$bootstrap->temp_lib_dir || 'templib'
l!l
00
MC/DC0%0/1
$bootstrap->temp_lib_dir || 'templib'
$bootstrap->temp_lib_dir
Truth table0%0/2
A
A= $bootstrap->temp_lib_dir
Aresult
11
00
574 0 return File::Spec->catdir( $bootstrap->website_dir, $lib_dir );
575 }
576  
577 0 ▶sub lookup_temp_lib_refresh_filename {
Subroutine lookup_temp_lib_refresh_filename: not called CC=1 SCAR=6.9
Pod undocumented
578 0 return 'refresh.txt';
579 }
580  
581 0 ▶sub lookup_override_action_filename {
Subroutine lookup_override_action_filename: not called CC=1 SCAR=6.9
Pod undocumented
582 0 return 'action_override.ini';
583 }
584  
585 0 ▶sub lookup_override_spops_filename {
Subroutine lookup_override_spops_filename: not called CC=1 SCAR=6.9
Pod undocumented
586 0 return 'spops_override.ini';
587 }
588  
589  
590 ########################################
591 # LOOKUPS, OTHER
592  
593 0 ▶sub lookup_session_config {
Subroutine lookup_session_config: not called CC=1 SCAR=6.9
Pod undocumented
594 0 my ( $self ) = @_;
595 0 return $self->server_config->{session_info};
596 }
597  
598 0 ▶sub lookup_login_config {
Subroutine lookup_login_config: not called CC=1 SCAR=6.9
Pod undocumented
599 0 my ( $self ) = @_;
600 0 return $self->server_config->{login};
601 }
602  
603 0 ▶sub lookup_mail_config {
Subroutine lookup_mail_config: not called CC=1 SCAR=6.9
Pod undocumented
604 0 my ( $self ) = @_;
605 0 return $self->server_config->{mail};
606 }
607  
608 0 ▶sub lookup_language_config {
Subroutine lookup_language_config: not called CC=1 SCAR=6.9
Pod undocumented
609 0 my ( $self ) = @_;
610 0 return $self->server_config->{language};
611 }
612  
613 0 ▶sub lookup_cache_config {
Subroutine lookup_cache_config: not called CC=1 SCAR=6.9
Pod undocumented
614 0 my ( $self ) = @_;
615 0 return $self->server_config->{cache};
616 }
617  
618 0 ▶sub lookup_config_watcher_config {
Subroutine lookup_config_watcher_config: not called CC=1 SCAR=6.9
Pod undocumented
619 0 my ( $self ) = @_;
620 0 return $self->server_config->{config_watcher};
621 }
622  
623 0 ▶sub lookup_redirect_config {
Subroutine lookup_redirect_config: not called CC=1 SCAR=6.9
Pod undocumented
624 0 my ( $self ) = @_;
625 0 return $self->server_config->{redirect};
626 }
627  
628 0 ▶sub lookup_box_config {
Subroutine lookup_box_config: not called CC=1 SCAR=6.9
Pod undocumented
629 0 my ( $self ) = @_;
630 0 return $self->server_config->{box};
631 }
632  
633  
634 ########################################
635 # CLASS LOOKUP
636  
637  
638 0 ▶sub lookup_class {
Subroutine lookup_class: not called CC=2 SCAR=17.9
Pod undocumented
639 0 my ( $self, $name ) = @_;
640 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
641 0 return $self->server_config->{system_class}{ $name };
642 }
643 0 return $self->server_config->{system_class};
644 }
645  
646  
647 # Config shortcut
648  
649 # NOTE: Coupling to OI2::URL->create_from_action with the
650 # 'url_primary' key.
651  
652 0 ▶sub action_table {
Subroutine action_table: not called CC=9 SCAR=45.0
Pod undocumented
653 0 my ( $self, $table ) = @_;
654 0 ▶ $log_act ||= get_logger( LOG_ACTION );
Condition0%0/3
$log_act ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_act ||= get_logger("OI2.ACTION")
$log_act get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $log_actB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
655 0 ▶ if ( $table ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table) 0 0 0
656 0 ▶ $log_act->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_info and $log_act->info("Assigning new action table") 0 0 0
657 $log_act->info( "Assigning new action table" );
658 0 $self->server_config->{action} = $table;
659 0 my %url_to_name = ();
660 0 ▶ while ( my ( $name, $info ) = each %{ $table } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$table;}) 0 0 0
661 0 ▶ next if ( $info->{redir} );
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"redir"} 0 0 0
662 0 ▶ $log_act->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log_act->is_debug and $log_act->debug("Finding URL(s) for action '${name}'") 0 0 0
663 $log_act->debug( "Finding URL(s) for action '$name'" );
664 0 my $action = eval { OpenInteract2::Action->new( $info ) };
665 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
666 0 $log_act->error(
667 "Failed to create action '$name' when assigned a new ",
668 "set of action configurations. Will remove action data ",
669 "from action table. Error: $@" );
670 0 delete $self->server_config->{action}->{ $name };
671 }
672 else {
673 0 my $respond_urls = $action->get_dispatch_urls;
674 0 $url_to_name{ $_ } = $name for ( @{ $respond_urls } );
675 0 $info->{url_primary} = $respond_urls->[0];
676 }
677 }
678 0 $self->server_config->{action_url} = \%url_to_name;
679 }
680 0 return $self->server_config->{action};
681 }
682  
683  
684 # Config shortcut
685  
686 0 ▶sub spops_config {
Subroutine spops_config: not called CC=4 SCAR=30.0
Pod undocumented
687 0 my ( $self, $table ) = @_;
688 0 ▶ $log_spops ||= get_logger( LOG_SPOPS );
Condition0%0/3
$log_spops ||= get_logger("OI2.SPOPS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log_spops ||= get_logger("OI2.SPOPS")
$log_spops get_logger("OI2.SPOPS")
Truth table0%0/3
A ||= B
A= $log_spopsB= get_logger("OI2.SPOPS")
ABresult
1X1
011
000
689 0 ▶ if ( $table ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table) 0 0 0
690 0 ▶ $log_spops->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log_spops->is_info and $log_spops->info("Assigning new SPOPS configuration") 0 0 0
691 $log_spops->info( "Assigning new SPOPS configuration" );
692 0 $self->server_config->{SPOPS} = $table;
693 }
694 0 return $self->server_config->{SPOPS};
695 }
696  
697 # Config shortcut
698  
699 0 ▶sub assign_datasource_config {
Subroutine assign_datasource_config: not called CC=3 SCAR=24.8
Pod undocumented
700 0 my ( $self, $name, $config ) = @_;
701 0 ▶ unless ( $name and $config ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name and $config) 0 0 0
Condition0%0/3
$name and $config
!ll&&!rl&&r
000
MC/DC0%0/2
$name and $config
$name $config
Truth table0%0/3
A and B
A= $nameB= $config
ABresult
0X0
100
111
702 0 return;
703 }
704 0 $self->server_config->{datasource}{ $name } = $config;
705 0 return $config;
706 }
707  
708 0 ▶sub lookup_datasource_config {
Subroutine lookup_datasource_config: not called CC=2 SCAR=17.9
Pod undocumented
709 0 my ( $self, $name ) = @_;
710 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
711 0 return $self->server_config->{datasource}{ $name };
712 }
713 0 return $self->server_config->{datasource};
714 }
715  
716 0 ▶sub lookup_datasource_type_config {
Subroutine lookup_datasource_type_config: not called CC=2 SCAR=17.9
Pod undocumented
717 0 my ( $self, $type ) = @_;
718 0 ▶ if ( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 0 0 0
719 0 return $self->server_config->{datasource_type}{ $type };
720 }
721 0 return $self->server_config->{datasource_type};
722 }
723  
724 0 ▶sub lookup_system_datasource_name {
Subroutine lookup_system_datasource_name: not called CC=1 SCAR=6.9
Pod undocumented
725 0 my ( $self ) = @_;
726 0 return $self->server_config->{datasource_config}{system};
727 }
728  
729 0 ▶sub lookup_default_datasource_name {
Subroutine lookup_default_datasource_name: not called CC=1 SCAR=6.9
Pod undocumented
730 0 my ( $self ) = @_;
731 0 return $self->server_config->{datasource_config}{spops};
732 }
733  
734 0 ▶sub lookup_default_ldap_datasource_name {
Subroutine lookup_default_ldap_datasource_name: not called CC=1 SCAR=6.9
Pod undocumented
735 0 my ( $self ) = @_;
736 0 return $self->server_config->{datasource_config}{ldap};
737 }
738  
739 0 ▶sub lookup_default_object_id {
Subroutine lookup_default_object_id: not called CC=2 SCAR=17.9
Pod undocumented
740 0 my ( $self, $name ) = @_;
741 0 ▶ if ( $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
742 0 return $self->server_config->{default_objects}{ $name };
743 }
744 0 return $self->server_config->{default_objects};
745 }
746  
747 0 ▶sub lookup_id_config {
Subroutine lookup_id_config: not called CC=2 SCAR=17.9
Pod undocumented
748 0 my ( $self, $definition ) = @_;
749 0 ▶ if ( $definition ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($definition) 0 0 0
750 0 return $self->{server_config}{id}{ $definition };
751 }
752 0 return $self->{server_config}{id};
753 }
754  
755  
756 ########################################
757 # GLOBAL RESOURCES
758  
759 # Get the named datasource -- just pass along the request to the
760 # DatasourceManager
761  
762 0 ▶sub datasource {
Subroutine datasource: not called CC=2 SCAR=17.9
Pod documented
763 0 my ( $self, $name ) = @_;
764  
765 # TODO: Why choose the 'system' default here?
766 0 ▶ $name ||= $self->server_config->{datasource_config}{system};
Condition0%0/3
$name ||= $self->server_config->{"datasource_config"}{"system"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $self->server_config->{"datasource_config"}{"system"}
$name $self->server_config->{"datasource_config"}{"system"}
Truth table0%0/3
A ||= B
A= $nameB= $self->server_config->{"datasource_config"}{"system"}
ABresult
1X1
011
000
767 0 return OpenInteract2::DatasourceManager->datasource( $name );
768 }
769  
770 0 ▶sub content_generator {
Subroutine content_generator: not called CC=1 SCAR=6.9
Pod undocumented
771 0 my ( $self, $name ) = @_;
772 0 return OpenInteract2::ContentGenerator->instance( $name );
773 }
774  
775  
776 0 ▶sub assign_default_language_handle {
Subroutine assign_default_language_handle: not called CC=1 SCAR=6.9
Pod undocumented
777 0 my ( $self, $lh ) = @_;
778 0 $DEFAULT_LANGUAGE_HANDLE = $lh
779 }
780  
781 0 ▶sub language_handle {
Subroutine language_handle: not called CC=4 SCAR=30.0
Pod undocumented
782 0 my ( $self, $lang ) = @_;
783 0 ▶ if ( $self->request and my $h = $self->request->language_handle ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->request and my $h = $self->request->language_handle) { } 0 0 0
elsif ($lang) { } 0 0 0
Condition0%0/3
$self->request and my $h = $self->request->language_handle
!ll&&!rl&&r
000
MC/DC0%0/2
$self->request and my $h = $self->request->language_handle
$self->request my $h = $self->request->language_handle
Truth table0%0/3
A and B
A= $self->requestB= my $h = $self->request->language_handle
ABresult
0X0
100
111
784 0 return $h;
785 }
786 elsif ( $lang ) {
787 0 return OpenInteract2::I18N->get_handle( $lang );
788 }
789 else {
790 0 return $DEFAULT_LANGUAGE_HANDLE;
791 }
792 }
793  
794 0 ▶sub cleanup_request {
Subroutine cleanup_request: not called CC=2 SCAR=17.9
Pod undocumented
795 0 my ( $self ) = @_;
796 0 $self->set( $_, undef ) for ( @REQUEST_FIELDS );
797  
798 # TODO: These two methods Needed?
799 0 $self->clear_global_attributes;
800 0 $self->clear_exceptions;
801 }
802  
803  
804 # Shortcut -- use to check security on classes that are not derived
805 # from SPOPS::Secure, or from other resources
806  
807 0 ▶sub check_security {
Subroutine check_security: not called CC=7 SCAR=40.3
Pod undocumented
808 0 my ( $self, $params ) = @_;
809 0 my $log_sec = get_logger( LOG_SECURITY );
810  
811 # TODO: make static at startup...
812 0 my $security_class = $self->lookup_object( 'security' );
813  
814 my %security_info = ( security_object_class => $security_class,
815 class => $params->{class},
816 object_id => $params->{object_id},
817 user => $params->{user},
818 0 group => $params->{group} );
819 0 my $request = $self->request;
820 0 ▶ if ( $request and $request->auth_is_logged_in ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request and $request->auth_is_logged_in) 0 0 0
Condition0%0/3
$request and $request->auth_is_logged_in
!ll&&!rl&&r
000
MC/DC0%0/2
$request and $request->auth_is_logged_in
$request $request->auth_is_logged_in
Truth table0%0/3
A and B
A= $requestB= $request->auth_is_logged_in
ABresult
0X0
100
111
821 0 ▶ $log_sec->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log_sec->is_debug and $log_sec->debug("Assigning user/group from login") 0 0 0
822 $log_sec->debug( "Assigning user/group from login" );
823 0 ▶ $security_info{user} ||= $request->auth_user;
Condition0%0/3
$security_info{"user"} ||= $request->auth_user
l!l&&r!l&&!r
000
MC/DC0%0/2
$security_info{"user"} ||= $request->auth_user
$security_info{"user"} $request->auth_user
Truth table0%0/3
A ||= B
A= $security_info{"user"}B= $request->auth_user
ABresult
1X1
011
000
824 0 ▶ $security_info{group} ||= $request->auth_group;
Condition0%0/3
$security_info{"group"} ||= $request->auth_group
l!l&&r!l&&!r
000
MC/DC0%0/2
$security_info{"group"} ||= $request->auth_group
$security_info{"group"} $request->auth_group
Truth table0%0/3
A ||= B
A= $security_info{"group"}B= $request->auth_group
ABresult
1X1
011
000
825 }
826 $log_sec->is_debug &&
827 0 ▶ $log_sec->debug( "Checking security for '$params->{class}' ",
Branch: 1 branch
BranchTrueFalseTotal
$log_sec->is_debug and $log_sec->debug(qq[Checking security for '$params->{"class"}' ], qq['$params->{"object_id"}' with '${security_class}']) 0 0 0
828 "'$params->{object_id}' with '$security_class'" );
829 0 return SPOPS::Secure->check_security( \%security_info );
830 }
831  
832  
833 ########################################
834 # EXCEPTIONS
835  
836 # Exception shortcuts
837 # TODO: remove?
838  
839 0 ▶sub throw { shift; goto &OpenInteract2::Exception::throw( @_ ) }
Subroutine throw: not called CC=1 SCAR=6.9
Pod undocumented
840  
841  
842 # outside world doesn't need to know...
843  
844 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
845 0 shift;
846 0 my $output = '';
847 0 $output .= Dumper( $_ ) for ( @_ );
848 0 return $output;
849 }
850  
851 87 1;
852  
853 __END__
« OpenInteract2/Log/OIAppender.pm ↑ Summary OpenInteract2/Manage/Website/CleanOrphanedUsers.pm »