OpenInteract2/Setup/CheckDatasources.pm

filter: Statementstmt 40.0% 20 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 35.1% 26 / 74 CC 7 SCAR 34.2
CC
7
Cov
32%
execute
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 30.6
« OpenInteract2/Request/Standalone.pm ↑ Summary OpenInteract2/Response/LWP.pm »
1 package OpenInteract2::Setup::CheckDatasources;
2  
3 # $Id: CheckDatasources.pm,v 1.3 2005/03/18 04:09:51 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Setup );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 87 $OpenInteract2::Setup::CheckDatasources::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
12  
13 87 my ( $log );
14  
15 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
16 87 return 'check datasources';
17 }
18  
19 0 ▶sub execute {
Subroutine execute: not called CC=7 SCAR=40.3
Pod undocumented
20 0 my ( $self, $ctx ) = @_;
21 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
22  
23 0 my $server_config = $ctx->server_config;
24 0 my $ds_manager_class = $server_config->{datasource_config}{manager};
25 0 OpenInteract2::Setup->new(
26 'require classes',
27 classes => $ds_manager_class,
28 classes_type => 'Datasource Manager'
29 )->run();
30 0 $ctx->datasource_manager( $ds_manager_class );
31 0 $log->info( "Assigned datasource manager ok" );
32  
33 0 my %all_datasource_config = %{ $ctx->lookup_datasource_config };
34 0 my %ds_to_manager = ();
35 0 my %seen_types = ();
36  
37 # Check manager/SPOPS classes...
38 0 ▶ while ( my ( $ds_name, $ds_info ) = each %all_datasource_config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %all_datasource_config) 0 0 0
39 0 $log->info( "Checking datasource '$ds_name'..." );
40 0 ▶ unless ( ref $ds_info eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ds_info eq "HASH") 0 0 0
41 0 oi_error "Datasource '$ds_name' does not have its configuration ",
42 "defined in the server configuration.";
43 }
44 0 my $ds_type = $ds_info->{type};
45 0 my $ds_type_info = $ctx->lookup_datasource_type_config( $ds_type );
46 0 ▶ unless ( ref $ds_type_info eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ds_type_info eq "HASH") 0 0 0
47 0 oi_error "Datasource type '$ds_type' defined in datasource ",
48 "'$ds_name' but no type information defined in the ",
49 "server config under 'datasource_type.$ds_type'";
50 }
51 0 $log->info( "Datasource '$ds_name' has valid type '$ds_type'" );
52 0 my $ds_config_handler = $ds_type_info->{spops_config};
53 0 my $ds_conn_handler = $ds_type_info->{connection_manager};
54 0 $ds_to_manager{ $ds_name } = $ds_conn_handler;
55 0 ▶ next if ( $seen_types{ $ds_type } );
Branch: 1 branch
BranchTrueFalseTotal
if $seen_types{$ds_type} 0 0 0
56  
57 0 OpenInteract2::Setup->new(
58 'require classes',
59 classes => [ $ds_config_handler, $ds_conn_handler ],
60 classes_type => "Datasource $ds_type support"
61 )->run();
62 0 $seen_types{ $ds_type }++;
63 }
64  
65 # now do any runtime munging...
66 0 ▶ while ( my ( $ds_name, $ds_info ) = each %all_datasource_config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %all_datasource_config) 0 0 0
67 0 my $ds_conn_handler = $ds_to_manager{ $ds_name };
68 0 my $new_info = $ds_conn_handler->resolve_datasource_info(
69 $ds_name, $ds_info
70 );
71 0 $ctx->assign_datasource_config( $ds_name, $new_info );
72 }
73
74 }
75  
76 87 OpenInteract2::Setup->register_factory_type( get_name() => __PACKAGE__ );
77  
78 87 1;
79  
80 __END__
« OpenInteract2/Request/Standalone.pm ↑ Summary OpenInteract2/Response/LWP.pm »