OpenInteract2/Config/Initializer.pm

filter: Statementstmt 16.6% 40 / 241 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 58 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 29.6% 8 / 27 Podpod 0.0% 0 / 2 totaltotal 10.0% 48 / 476 CC 86 SCAR 42.3
CC
86
Cov
10%
read_observers
156.0
_spops_set_hasa
156.0
_spops_creation_security
110.0
CRAP 68.5
« OpenInteract2/Setup/CreateTemporaryLibraryDirectory.pm ↑ Summary OpenInteract2/Config/PerlFile.pm »
1 package OpenInteract2::Config::Initializer;
2  
3 # $Id: Initializer.pm,v 1.24 2005/03/18 04:09:50 lachoy Exp $
4  
5 87 ▶use base qw( Class::Observable );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 87 ▶use OpenInteract2::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 87 $OpenInteract2::Config::Initializer::VERSION = sprintf("%d.%02d", q$Revision: 1.24 $ =~ /(\d+)\.(\d+)/);
15  
16 87 my ( $log );
17  
18 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
19 0 my ( $class ) = @_;
20 0 return bless( {}, $class );
21 }
22  
23 0 ▶sub read_observers {
Subroutine read_observers: not called CC=12 SCAR=50.5
Pod undocumented
24 0 my ( $class ) = @_;
25 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
26  
27 0 my @conf_watchers = ();
28  
29 # ...from the server
30 0 my $config_watcher = CTX->lookup_config_watcher_config;
31 0 ▶ if ( ref $config_watcher eq 'HASH' and
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config_watcher eq "HASH" and ref $config_watcher->{"class"} eq "ARRAY") 0 0 0
Condition0%0/3
ref $config_watcher eq "HASH" and ref $config_watcher->{"class"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $config_watcher eq "HASH" and ref $config_watcher->{"class"} eq "ARRAY"
ref $config_watcher eq "HASH" ref $config_watcher->{"class"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $config_watcher eq "HASH"B= ref $config_watcher->{"class"} eq "ARRAY"
ABresult
0X0
100
111
32 ref $config_watcher->{class} eq 'ARRAY' ) {
33 0 push @conf_watchers, @{ $config_watcher->{class} };
34 }
35  
36 # ...from packages
37 0 ▶ my $packages = CTX->packages || [];
Condition0%0/2
CTX()->packages || []
l!l
00
MC/DC0%0/1
CTX()->packages || []
CTX()->packages
Truth table0%0/2
A
A= CTX()->packages
Aresult
11
00
38 0 foreach my $package ( @{ $packages } ) {
39 0 ▶ next unless ( $package );
Branch: 1 branch
BranchTrueFalseTotal
unless $package 0 0 0
40 0 my $config = $package->config;
41 0 ▶ next unless ( $config );
Branch: 1 branch
BranchTrueFalseTotal
unless $config 0 0 0
42 0 my $config_watcher = $config->config_watcher;
43 0 ▶ next unless ( $config_watcher );
Branch: 1 branch
BranchTrueFalseTotal
unless $config_watcher 0 0 0
44 0 foreach my $watcher_class ( @{ $config_watcher } ) {
45 0 eval "require $watcher_class";
46 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
47 0 oi_error "Cannot find configured watcher '$watcher_class' ",
48 "from package '", $package->name, "': $@";
49 }
50 0 $log->info( "Required watcher '$watcher_class' ok" );
51 0 push @conf_watchers, $watcher_class;
52 }
53 }
54  
55 0 foreach my $watcher_class ( @conf_watchers ) {
56 0 __PACKAGE__->add_observer( $watcher_class );
57 0 $log->info( "Added custom config observer '$watcher_class'" );
58 }
59  
60 }
61  
62 ########################################
63 # SPOPS INITIALIZATION BEHAVIORS
64  
65 0 ▶sub _spops_normalize_params {
Subroutine _spops_normalize_params: not called CC=3 SCAR=24.8
66 0 my ( $init, $type, $config ) = @_;
67 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
68 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
69 0 $log->info( "Normalizing parameters for SPOPS '$config->{key}'" );
70  
71 0 my @list_params = qw( isa rules_from fulltext_field );
72 0 _normalize_list( $config, \@list_params );
73  
74 0 my @hash_params = qw();
75 0 _normalize_hash( $config, \@hash_params );
76 }
77  
78 0 ▶sub _spops_security {
Subroutine _spops_security: not called CC=5 SCAR=34.0
79 0 my ( $init, $type, $config ) = @_;
80 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
81 0 ▶ return unless ( $config->{is_secure} and $config->{is_secure} eq 'yes' );
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"is_secure"} and $config->{"is_secure"} eq "yes" 0 0 0
Condition0%0/3
$config->{"is_secure"} and $config->{"is_secure"} eq "yes"
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"is_secure"} and $config->{"is_secure"} eq "yes"
$config->{"is_secure"} $config->{"is_secure"} eq "yes"
Truth table0%0/3
A and B
A= $config->{"is_secure"}B= $config->{"is_secure"} eq "yes"
ABresult
0X0
100
111
82 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
83 0 $log->info( "Adding security to [$config->{key}: $config->{class}]" );
84 0 unshift @{ $config->{isa} }, 'SPOPS::Secure';
85 }
86  
87 0 ▶sub _spops_creation_security {
Subroutine _spops_creation_security: not called CC=10 SCAR=47.0
88 0 my ( $init, $type, $config ) = @_;
89 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
90 0 ▶ return unless ( ref $config->{creation_security} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config->{"creation_security"} eq "HASH" 0 0 0
91  
92 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
93 0 $log->info( "Checking 'creation_security' rules for ",
94 "[$config->{key}: $config->{class}]" );
95 my %create = ( u => $config->{creation_security}{user},
96 0 w => $config->{creation_security}{world} );
97  
98 0 my $default_objects = CTX->lookup_default_object_id;
99 0 my %groups = ();
100 0 ▶ if ( my $group_levels = $config->{creation_security}{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $group_levels = $config->{"creation_security"}{"group"}) 0 0 0
101 my @all_group_levels = ( ref $group_levels eq 'ARRAY' )
102 0 ▶ ? @{ $group_levels } : ( $group_levels );
Branch: 1 branch
BranchTrueFalseTotal
ref $group_levels eq 'ARRAY' ? : 0 0 0
103 0 foreach my $group_pair ( @all_group_levels ) {
104 0 my ( $gid, $gl ) = split /\s*:\s*/, $group_pair, 2;
105 0 ▶ if ( $gid =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gid =~ /\D/) 0 0 0
106 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Group ID [$gid] not a #, changing") 0 0 0
107 $log->debug( "Group ID [$gid] not a #, changing" );
108 0 $gid = $default_objects->{ $gid };
109 }
110 0 $groups{ $gid } = $gl;
111 }
112 }
113 0 $create{g} = \%groups;
114 0 $config->{creation_security} = \%create;
115 $log->is_debug &&
116 $log->debug( "Final security: ",
117 0 ▶ CTX->dump( $config->{creation_security} ) );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Final security: ", CTX()->dump($config->{"creation_security"})) 0 0 0
118 }
119  
120 0 ▶sub _spops_date_conversion {
Subroutine _spops_date_conversion: not called CC=9 SCAR=45.0
121 0 my ( $init, $type, $config ) = @_;
122 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
123 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
124  
125 0 my $DFK = 'convert_date_field';
126 0 ▶ $config->{ $DFK } ||= [];
Condition0%0/2
$config->{$DFK} ||= []
l!l
00
MC/DC0%0/1
$config->{$DFK} ||= []
$config->{$DFK}
Truth table0%0/2
A
A= $config->{$DFK}
Aresult
11
00
127 0 ▶ unless ( ref $config->{ $DFK } eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $config->{$DFK} eq "ARRAY") 0 0 0
128 0 $config->{ $DFK } = [ $config->{ $DFK } ];
129 }
130  
131 # First check to see if we have any date fields
132  
133 0 ▶ return unless ( scalar @{ $config->{ $DFK } } > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$config->{$DFK};} > 0 0 0 0
134  
135 $log->info( "Setting up [$config->{class}] to autoconvert ",
136 0 "its date fields: ", join( ', ', @{ $config->{ $DFK } } ) );
137  
138 0 $config->{convert_date_class} = 'DateTime';
139 0 my %existing_rules = map { $_ => 1 } @{ $config->{rules_from} };
140 0 ▶ unless ( $existing_rules{ 'SPOPS::Tool::DateConvert' } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($existing_rules{"SPOPS::Tool::DateConvert"}) 0 0 0
141 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Adding date conversion tool to rules") 0 0 0
142 $log->debug( "Adding date conversion tool to rules" );
143 0 push @{ $config->{rules_from} }, 'SPOPS::Tool::DateConvert';
144 }
145  
146 # TODO: Be able to set a default format for all databases
147  
148 0 ▶ unless ( $config->{convert_date_format} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"convert_date_format"}) 0 0 0
149 0 my $default_format = '%Y-%m-%d %H:%M:%S';
150 0 $log->warn( "SPOPS object [$config->{key}: $config->{class}] does ",
151 "not have a conversion date format set. This is ",
152 "STRONGLY encouraged -- please look at ",
153 "'OpenInteract2::Manual::SPOPS' under 'DATE ",
154 "CONVERSION' for more information. (Using default ",
155 "'$default_format')" );
156 0 $config->{convert_date_format} = $default_format;
157 }
158 }
159  
160 0 ▶sub _spops_fulltext {
Subroutine _spops_fulltext: not called CC=7 SCAR=40.3
161 0 my ( $init, $type, $config ) = @_;
162 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
163 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
164 0 ▶ if ( defined $config->{is_searchable} and $config->{is_searchable} eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"is_searchable"} and $config->{"is_searchable"} eq "yes") 0 0 0
Condition0%0/3
defined $config->{"is_searchable"} and $config->{"is_searchable"} eq "yes"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $config->{"is_searchable"} and $config->{"is_searchable"} eq "yes"
defined $config->{"is_searchable"} $config->{"is_searchable"} eq "yes"
Truth table0%0/3
A and B
A= defined $config->{"is_searchable"}B= $config->{"is_searchable"} eq "yes"
ABresult
0X0
100
111
165 0 ▶ if ( defined $config->{fulltext_field} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{'fulltext_field'}) { } 0 0 0
166 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Adding fulltext indexing for ", qq[[$config->{"key"}: $config->{"class"}]]) 0 0 0
167 $log->debug( "Adding fulltext indexing for ",
168 "[$config->{key}: $config->{class}]" );
169 0 unshift @{ $config->{isa} }, 'OpenInteract2::FullTextRules';
170 }
171 else {
172 0 $log->warn( "You set 'is_searchable' for [$config->{key}: ",
173 "$config->{class}] but you didn't list any ",
174 "fields in 'fulltext_field' so nothing will ",
175 "be indexed." );
176 }
177 }
178 }
179  
180 # Changes:
181 # [user has_a]
182 # My::User = updater: updated_by; poster: posted_by
183  
184 # To:
185 # user => {
186 # has_a => {
187 # 'My::User' => {
188 # updater => 'updated_by',
189 # poster => 'posted_by',
190 # }
191  
192 0 ▶sub _spops_set_hasa {
Subroutine _spops_set_hasa: not called CC=12 SCAR=50.5
193 0 my ( $init, $type, $config ) = @_;
194 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
195 0 my $hasa_conf = $config->{has_a};
196 0 ▶ return unless ( ref $hasa_conf eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hasa_conf eq "HASH" 0 0 0
197 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
198 0 ▶ $log->is_info && $log->info( "Modifying has_a for '$config->{key}'" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info(qq[Modifying has_a for '$config->{"key"}']) 0 0 0
199  
200 0 foreach my $hasa_class ( keys %{ $hasa_conf } ) {
201 0 my $mappings = $hasa_conf->{ $hasa_class };
202 0 ▶ if ( ref $mappings eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mappings eq "ARRAY") 0 0 0
203 0 $mappings = join( '; ', @{ $mappings } );
204 }
205 $log->is_info &&
206 0 ▶ $log->info( "Will replace '$mappings' within ",
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Will replace '${mappings}' within ", qq['$config->{"key"}.has_a']) 0 0 0
207 "'$config->{key}.has_a'" );
208 0 my @pieces = split /\s*;\s*/, $mappings;
209 0 my %replacement = ();
210 0 foreach my $piece ( @pieces ) {
211 0 my ( $name, $field ) = split /\s*:\s*/, $piece, 2;
212 0 ▶ next unless ( $name and $field );
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $field 0 0 0
Condition0%0/3
$name and $field
!ll&&!rl&&r
000
MC/DC0%0/2
$name and $field
$name $field
Truth table0%0/3
A and B
A= $nameB= $field
ABresult
0X0
100
111
213 0 $replacement{ $name } = $field;
214 0 ▶ $log->is_info && $log->info( "Setting $name = $field" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Setting $name = $field") 0 0 0
215 }
216 0 $config->{ $hasa_class } = \%replacement;
217 }
218 }
219  
220 # DBI-only
221  
222 0 ▶sub _config_is_dbi {
Subroutine _config_is_dbi: not called CC=1 SCAR=6.9
223 0 my ( $config ) = @_;
224 0 my $ds_info = CTX->lookup_datasource_config( $config->{datasource} );
225 0 return ( $ds_info->{type} eq 'DBI' );
226 }
227  
228 0 ▶sub _spops_discover_field {
Subroutine _spops_discover_field: not called CC=6 SCAR=37.4
229 0 my ( $init, $type, $config ) = @_;
230 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
231 0 ▶ return unless ( _config_is_dbi( $config ) );
Branch: 1 branch
BranchTrueFalseTotal
unless _config_is_dbi($config) 0 0 0
232 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
233 0 $log->info( "Adding field discovery for '$config->{key}'" );
234  
235 # use both conditions to get around 'uninitialized' warning under -w
236  
237 0 ▶ if ( $config->{field_discover} and $config->{field_discover} eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"field_discover"} and $config->{"field_discover"} eq "yes") 0 0 0
Condition0%0/3
$config->{"field_discover"} and $config->{"field_discover"} eq "yes"
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"field_discover"} and $config->{"field_discover"} eq "yes"
$config->{"field_discover"} $config->{"field_discover"} eq "yes"
Truth table0%0/3
A and B
A= $config->{"field_discover"}B= $config->{"field_discover"} eq "yes"
ABresult
0X0
100
111
238 0 push @{ $config->{rules_from} }, 'SPOPS::Tool::DBI::DiscoverField';
239 }
240 }
241  
242 0 ▶sub _spops_set_dbi {
Subroutine _spops_set_dbi: not called CC=4 SCAR=30.0
243 0 my ( $init, $type, $config ) = @_;
244 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
245 0 ▶ return unless ( _config_is_dbi( $config ) );
Branch: 1 branch
BranchTrueFalseTotal
unless _config_is_dbi($config) 0 0 0
246 0 my $ds_info = CTX->lookup_datasource_config( $config->{datasource} );
247 0 my $spops_class = $ds_info->{spops};
248  
249 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
250 0 $log->info( "Setting '$spops_class' and standards in 'isa' ",
251 "for '$config->{key}'" );
252  
253 0 push @{ $config->{isa} }, ( $spops_class, 'SPOPS::DBI' );
254 0 unshift @{ $config->{isa} }, 'OpenInteract2::SPOPS::DBI';
255 }
256  
257 # LDAP-only
258  
259 0 ▶sub _spops_set_ldap {
Subroutine _spops_set_ldap: not called CC=3 SCAR=24.8
260 0 my ( $init, $type, $config ) = @_;
261 0 ▶ return unless ( $type eq 'spops' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "spops" 0 0 0
262  
263 0 my $ds_info = CTX->lookup_datasource_config( $config->{datasource} );
264 0 ▶ return unless ( $ds_info->{type} eq 'LDAP' );
Branch: 1 branch
BranchTrueFalseTotal
unless $ds_info->{"type"} eq "LDAP" 0 0 0
265  
266 0 unshift @{ $config->{isa} }, 'OpenInteract2::SPOPS::LDAP';
267 0 push @{ $config->{isa} }, 'SPOPS::LDAP';
268 }
269  
270  
271 87 __PACKAGE__->add_observer( \&_spops_normalize_params );
272 87 __PACKAGE__->add_observer( \&_spops_security );
273 87 __PACKAGE__->add_observer( \&_spops_creation_security );
274 87 __PACKAGE__->add_observer( \&_spops_date_conversion );
275 87 __PACKAGE__->add_observer( \&_spops_fulltext );
276 87 __PACKAGE__->add_observer( \&_spops_set_hasa );
277 87 __PACKAGE__->add_observer( \&_spops_set_dbi );
278 87 __PACKAGE__->add_observer( \&_spops_discover_field );
279 87 __PACKAGE__->add_observer( \&_spops_set_ldap );
280  
281  
282 ########################################
283 # ACTION INITIALIZATION BEHAVIORS
284  
285 0 ▶sub _action_normalize_params {
Subroutine _action_normalize_params: not called CC=3 SCAR=24.8
286 0 my ( $init, $type, $config ) = @_;
287 0 ▶ return unless ( $type eq 'action' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "action" 0 0 0
288  
289 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
290 0 $log->info( "Normalizing params for action '$config->{name}'" );
291  
292 0 my @list_params = qw( url_alt task_valid task_invalid );
293 0 _normalize_list( $config, \@list_params );
294  
295 0 my @hash_params = qw( template_source cache_expire );
296 0 _normalize_hash( $config, \@hash_params );
297 }
298  
299 0 ▶sub _action_assign_defaults {
Subroutine _action_assign_defaults: not called CC=6 SCAR=37.4
300 0 my ( $init, $type, $config ) = @_;
301 0 ▶ return unless ( $type eq 'action' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "action" 0 0 0
302  
303 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
304 0 ▶ return if ( $config->{redir} );
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"redir"} 0 0 0
305 0 $log->info( "Assigning action defaults to '$config->{name}'" );
306 0 my $global_defaults = CTX->lookup_default_action_info;
307 0 ▶ while ( my ( $action_item, $action_value ) =
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$global_defaults;}) 0 0 0
308 0 each %{ $global_defaults } ) {
309 0 ▶ next if ( exists $config->{ $action_item } );
Branch: 1 branch
BranchTrueFalseTotal
if exists $config->{$action_item} 0 0 0
310 0 $config->{ $action_item } = $action_value;
311 }
312 }
313  
314 0 ▶sub _action_security_level {
Subroutine _action_security_level: not called CC=6 SCAR=37.4
315 0 my ( $init, $type, $config ) = @_;
316 0 ▶ return unless ( $type eq 'action' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "action" 0 0 0
317 0 ▶ return unless ( $config->{security} );
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"security"} 0 0 0
318  
319 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
320 0 $log->info( "Modifying verbose security for action '$config->{name}'" );
321  
322 0 ▶ if ( ref $config->{security} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config->{'security'} eq 'HASH') { } 0 0 0
323 0 foreach my $task ( keys %{ $config->{security} } ) {
324 0 my $verbose = uc $config->{security}{ $task };
325 0 $config->{security}{ $task } = _translate_security_to_level( $verbose );
326 }
327 }
328 else {
329 0 my $verbose = uc $config->{security};
330 0 $config->{security} = _translate_security_to_level( $verbose );
331 }
332 }
333  
334 0 ▶sub _translate_security_to_level {
Subroutine _translate_security_to_level: not called CC=2 SCAR=17.9
335 0 my ( $verbose ) = @_;
336 0 ▶ if ( $verbose =~ /^(NONE|SUMMARY|READ|WRITE)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose =~ /^(NONE|SUMMARY|READ|WRITE)$/i) 0 0 0
337 0 $verbose = OpenInteract2::Util->verbose_to_level( uc $verbose );
338 }
339 0 return int( $verbose );
340 }
341  
342 0 ▶sub _action_cache_params {
Subroutine _action_cache_params: not called CC=7 SCAR=40.3
343 0 my ( $init, $type, $config ) = @_;
344 0 ▶ return unless ( $type eq 'action' );
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "action" 0 0 0
345 0 ▶ return unless ( ref $config->{cache_param} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config->{"cache_param"} eq "HASH" 0 0 0
346  
347 0 ▶ $log ||= get_logger( LOG_INIT );
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
ABresult
1X1
011
000
348 0 $log->info( "Modifying cache params for action '$config->{name}'" );
349 0 foreach my $task ( keys %{ $config->{cache_param} } ) {
350 0 ▶ if ( ref $config->{cache_param}->{ $task } ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config->{"cache_param"}{$task} ne "ARRAY") 0 0 0
351 $config->{cache_param}->{ $task } =
352 ( $config->{cache_param}->{ $task } )
353 0 ▶ ? [ $config->{cache_param}->{ $task } ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$config->{'cache_param'}{$task} ? : 0 0 0
354 }
355  
356 # Task parameters are always in the same order...
357 $config->{cache_param}->{ $task } =
358 0 [ sort @{ $config->{cache_param}->{ $task } } ];
359 }
360 }
361  
362  
363 87 __PACKAGE__->add_observer( \&_action_normalize_params );
364 87 __PACKAGE__->add_observer( \&_action_assign_defaults );
365 87 __PACKAGE__->add_observer( \&_action_security_level );
366 87 __PACKAGE__->add_observer( \&_action_cache_params );
367  
368  
369 ########################################
370 # GENERIC STUFF
371  
372 0 ▶sub _normalize_list {
Subroutine _normalize_list: not called CC=4 SCAR=30.0
373 0 my ( $config, $list_params ) = @_;
374 0 foreach my $param ( @{ $list_params } ) {
375 0 ▶ if ( ! $config->{ $param } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $config->{$param}) { } 0 0 0
elsif (ref $config->{$param} ne 'ARRAY') { } 0 0 0
376 0 $config->{ $param } = [];
377 }
378 elsif ( ref $config->{ $param } ne 'ARRAY' ) {
379 0 $config->{ $param } = [ $config->{ $param } ];
380 }
381 }
382 }
383  
384 0 ▶sub _normalize_hash {
Subroutine _normalize_hash: not called CC=3 SCAR=24.8
385 0 my ( $config, $hash_params ) = @_;
386 0 foreach my $param ( @{ $hash_params } ) {
387 0 ▶ if ( ! defined $config->{ $param } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config->{$param}) 0 0 0
388 0 $config->{ $param } = {};
389 }
390 }
391 }
392  
393 87 1;
394  
395 __END__
« OpenInteract2/Setup/CreateTemporaryLibraryDirectory.pm ↑ Summary OpenInteract2/Config/PerlFile.pm »