| 1 | package OpenInteract2::Setup::ReadSPOPSConfig; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # $Id: ReadSPOPSConfig.pm,v 1.4 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 File::Spec::Functions qw( catfile ); | ||||||||||||||||||
|
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::Config::GlobalOverride; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 87 | ▶ | use OpenInteract2::Config::Initializer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 87 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 87 | $OpenInteract2::Setup::ReadSPOPSConfig::VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 87 | my ( $log ); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 87 | ▶ | sub get_name { | ||||||||||||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 19 | 87 | return 'read spops config'; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | ▶ | sub get_dependencies { | ||||||||||||||||||
|
Subroutine
get_dependencies: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 23 | 1 | return ( 'initialize actions' ); | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub execute { | ||||||||||||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my ( $self, $ctx ) = @_; | |||||||||||||||||||
| 28 | 0 | ▶ | $log ||= get_logger( LOG_INIT ); | ||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
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")
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | my %SPOPS = (); # will be the full SPOPS config | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | foreach my $package ( @{ $ctx->packages } ) { | |||||||||||||||||||
| 33 | 0 | $self->_assign_configs_from_package( $ctx, $package, \%SPOPS ); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | 0 | $self->_apply_global_spops_override( $ctx, \%SPOPS ); | |||||||||||||||||||
| 36 | 0 | $self->_notify_config_observers( \%SPOPS ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | $ctx->spops_config( \%SPOPS ); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub _assign_configs_from_package { | ||||||||||||||||||
|
Subroutine
_assign_configs_from_package: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 42 | 0 | my ( $self, $ctx, $package, $SPOPS ) = @_; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | my $default_datasource = $ctx->lookup_default_datasource_name; | |||||||||||||||||||
| 45 | 0 | $log->info( "Using default datasource '$default_datasource'" ); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | my $package_id = join( '-', $package->name, $package->version ); | |||||||||||||||||||
| 48 | 0 | $log->debug( "Reading SPOPS data from $package_id" ); | |||||||||||||||||||
| 49 | 0 | my $filenames = $package->get_spops_files; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | SPOPSFILE: | ||||||||||||||||||||
| 52 | 0 | foreach my $spops_file ( @{ $filenames } ) { | |||||||||||||||||||
| 53 | 0 | $log->debug( "SPOPS file: $spops_file" ); | |||||||||||||||||||
| 54 | 0 | my $ini = $self->_read_ini( $spops_file ); | |||||||||||||||||||
| 55 | 0 | ▶ | next SPOPSFILE unless ( $ini ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | foreach my $spops_key ( $ini->main_sections ) { | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # TODO: Throw an exception if this happens? | ||||||||||||||||||||
| 60 | 0 | ▶ | if ( $SPOPS->{ $spops_key } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | $log->error( "WARNING - Multiple SPOPS objects defined ", | |||||||||||||||||||
| 62 | "with the same key '$spops_key'. Overwriting data ", | ||||||||||||||||||||
| 63 | "from '$SPOPS->{ $spops_key }->{package_name}'" ); | ||||||||||||||||||||
| 64 | 0 | delete $SPOPS->{ $spops_key }; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # Put the alias inside the SPOPS object | ||||||||||||||||||||
| 68 | 0 | my %spops_assign = ( key => $spops_key ); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | # Then copy over all the object definition info | ||||||||||||||||||||
| 71 | 0 | ▶ | while ( my ( $key, $value ) = each %{ $ini->{ $spops_key } } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | $spops_assign{ $key } = $value; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # Set the package name/version this object came from, and | ||||||||||||||||||||
| 76 | # the default datasource | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | $spops_assign{package_name} = $package->name; | |||||||||||||||||||
| 79 | 0 | $spops_assign{package_version} = $package->version; | |||||||||||||||||||
| 80 | 0 | $spops_assign{package_config_file} = $spops_file; | |||||||||||||||||||
| 81 | 0 | ▶ | $spops_assign{datasource} ||= $default_datasource; | ||||||||||||||||||
|
Condition0%0/3
$spops_assign{"datasource"} ||= $default_datasource
MC/DC0%0/2
$spops_assign{"datasource"} ||= $default_datasource
$spops_assign{"datasource"}
$default_datasource
Truth table0%0/3
A ||= B
A= $spops_assign{"datasource"}B= $default_datasource
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | $SPOPS->{ $spops_key } = \%spops_assign; | |||||||||||||||||||
| 84 | 0 | $log->info( "Read in SPOPS config for object ", | |||||||||||||||||||
| 85 | "[$spops_key: $ini->{ $spops_key }{class}]" ); | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | sub _apply_global_spops_override { | ||||||||||||||||||
|
Subroutine
_apply_global_spops_override: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 92 | 0 | my ( $self, $ctx, $SPOPS ) = @_; | |||||||||||||||||||
| 93 | 0 | my $override_file = catfile( | |||||||||||||||||||
| 94 | $ctx->lookup_directory( 'config' ), | ||||||||||||||||||||
| 95 | $ctx->lookup_override_spops_filename() | ||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||
| 97 | 0 | ▶ | if ( -f $override_file ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 0 | my $overrider = OpenInteract2::Config::GlobalOverride->new({ | |||||||||||||||||||
| 99 | filename => $override_file | ||||||||||||||||||||
| 100 | }); | ||||||||||||||||||||
| 101 | 0 | $overrider->apply_rules( $SPOPS ); | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | sub _notify_config_observers { | ||||||||||||||||||
|
Subroutine
_notify_config_observers: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 106 | 0 | my ( $self, $SPOPS ) = @_; | |||||||||||||||||||
| 107 | 0 | my $initializer = OpenInteract2::Config::Initializer->new; | |||||||||||||||||||
| 108 | 0 | foreach my $spops_config ( values %{ $SPOPS } ) { | |||||||||||||||||||
| 109 | 0 | $initializer->notify_observers( 'spops', $spops_config ); | |||||||||||||||||||
| 110 | 0 | $log->info( "Notified observers of config for SPOPS ", | |||||||||||||||||||
| 111 | "[$spops_config->{key}: $spops_config->{class}]" ); | ||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 87 | OpenInteract2::Setup->register_factory_type( get_name() => __PACKAGE__ ); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 87 | 1; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||