« OpenInteract2/Setup/InitializeActions.pm
↑ Summary
OpenInteract2/Manage/Package/CreatePackage.pm »
| 1 | package OpenInteract2::Config::Bootstrap; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id: Bootstrap.pm,v 1.2 2005/03/18 04:09:50 lachoy 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 File::Basename qw( dirname ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 87 | ▶ | use File::Spec::Functions qw( :ALL ); | ||||||||||||||||||||||||||||||||||||||||
|
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::Config::Ini; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 87 | ▶ | use OpenInteract2::Constants qw( :log BOOTSTRAP_CONF_DIR BOOTSTRAP_CONF_FILE ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 87 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 87 | $OpenInteract2::Config::Bootstrap::VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 87 | my ( $log ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 87 | my @CONFIG_FIELDS = qw( website_dir temp_lib_dir package_dir | |||||||||||||||||||||||||||||||||||||||||
| 20 | config_type config_class config_dir config_file ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 87 | my @FIELDS = ( @CONFIG_FIELDS, 'filename' ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 87 | OpenInteract2::Config::Bootstrap->mk_accessors( @FIELDS ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my ( $class, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | $log ||= get_logger( LOG_CONFIG ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$log ||= get_logger("OI2.CONFIG")
MC/DC0%0/2
$log ||= get_logger("OI2.CONFIG")
$log
get_logger("OI2.CONFIG")
Truth table33%1/3
A ||= B
A= $logB= get_logger("OI2.CONFIG")
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $self = bless( {}, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $filename = $params->{filename}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $website_dir = $params->{website_dir}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | if ( ! $filename and $website_dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
not $filename and $website_dir
MC/DC0%0/2
not $filename and $website_dir
not $filename
$website_dir
Truth table33%1/3
not(A) and B
A= not $filenameB= $website_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $filename = $self->create_website_filename( $website_dir ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $self->website_dir( $website_dir ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # If the last directory of the specified file is 'conf', assume | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # that everything else is the website dir | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | ▶ | elsif ( $filename and ! $website_dir ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$filename and not $website_dir
MC/DC0%0/2
$filename and not $website_dir
$filename
not $website_dir
Truth table0%0/3
A and not(B)
A= $filenameB= not $website_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $filename = rel2abs( $filename ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my @dirs = splitdir( dirname( $filename ) ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( $dirs[-1] eq BOOTSTRAP_CONF_DIR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | pop @dirs; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->website_dir( catdir( @dirs ) ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if ( $filename and -f $filename ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filename and -f $filename
MC/DC0%0/2
$filename and -f $filename
$filename
-f $filename
Truth table33%1/3
A and B
A= $filenameB= -f $filename
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | $params = $self->read_config( $filename ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $self->filename( $filename ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | unless ( $self->config_dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | $self->config_dir( BOOTSTRAP_CONF_DIR ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $self->_initialize( $params ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | $log->debug( "Read bootstrap configuration ok, returning" ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub read_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_config: called CC=5 SCAR=17.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my ( $class, $filename ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | $log ||= get_logger( LOG_CONFIG ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$log ||= get_logger("OI2.CONFIG")
MC/DC0%0/2
$log ||= get_logger("OI2.CONFIG")
$log
get_logger("OI2.CONFIG")
Truth table33%1/3
A ||= B
A= $logB= get_logger("OI2.CONFIG")
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | unless ( -f $filename ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $msg = "Cannot open '$filename' for bootstrap server " . | |||||||||||||||||||||||||||||||||||||||||
| 70 | "configuration: file does not exist"; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $log->fatal( $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | oi_error $msg; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $ini = OpenInteract2::Config::Ini->new({ filename => $filename }); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | return {} unless ( $ini->{bootstrap} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my %params = (); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | while ( my ( $key, $value ) = each %{ $ini->{bootstrap} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | $params{ $key } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return \%params; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub create_website_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_website_filename: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my ( $class, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | unless ( $dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | oi_error "Must pass in website directory to create ", | |||||||||||||||||||||||||||||||||||||||||
| 87 | "bootstrap filename"; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return $class->create_filename( catdir( $dir, BOOTSTRAP_CONF_DIR ) ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub create_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_filename: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | my ( $class, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | unless ( $dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | oi_error "Must pass in directory to create bootstrap filename"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return catfile( $dir, BOOTSTRAP_CONF_FILE ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # OBJECT METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | foreach my $field ( @CONFIG_FIELDS ) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | ▶ | if ( $params->{ $field } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | $self->$field( $params->{ $field } ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | if ( $field =~ /dir$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | $self->clean_dir( $field ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub clean_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_dir: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | my ( $self, $prop ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | my $dir = $self->$prop(); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | if ( $dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | $dir =~ s|/$||; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 6 | $self->$prop( $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | return $dir; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub get_server_config_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_server_config_file: called CC=4 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | unless ( $self->website_dir and $self->config_dir and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->website_dir and $self->config_dir and $self->config_file
$self->website_dir and $self->config_dir
MC/DC0%0/3
$self->website_dir and $self->config_dir and $self->config_file
$self->website_dir
$self->config_dir
$self->config_file
Truth table25%1/4
A and B and C
A= $self->website_dirB= $self->config_dirC= $self->config_file
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | $self->config_file ) { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | oi_error sprintf( | |||||||||||||||||||||||||||||||||||||||||
| 134 | "Properties 'website_dir', 'config_dir' and 'config_file' must " . | ||||||||||||||||||||||||||||||||||||||||||
| 135 | "be defined to retrieve the config filename. Currently assigned " . | ||||||||||||||||||||||||||||||||||||||||||
| 136 | "as '%s', '%s' and '%s'", | ||||||||||||||||||||||||||||||||||||||||||
| 137 | $self->website_dir, $self->config_dir, $self->config_file | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $self->clean_dir( 'website_dir' ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->clean_dir( 'config_dir' ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | return catfile( $self->website_dir, | |||||||||||||||||||||||||||||||||||||||||
| 143 | $self->config_dir, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | $self->config_file ); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub save_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_config: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ( $self, ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # First ensure required fields are set | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my @empty_fields = grep { ! $self->$_() } @CONFIG_FIELDS; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ( scalar @empty_fields ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | oi_error "Cannot save bootstrap config: the following fields ", | |||||||||||||||||||||||||||||||||||||||||
| 155 | "must be defined: ", join( ", ", @empty_fields ); | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # If no filename create one from the website_dir | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | unless ( $self->filename() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $self->filename( | |||||||||||||||||||||||||||||||||||||||||
| 161 | $self->create_website_filename( $self->website_dir ) | ||||||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # Now store data into the INI and write it out | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $ini = OpenInteract2::Config::Ini->new(); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | foreach my $field ( @CONFIG_FIELDS ) { | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $ini->set( 'bootstrap', $field, $self->$field() ); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $ini->write_file( $self->filename() ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return $self->filename(); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 87 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||||||||||||||||