| 1 | package OpenInteract2::Config::IniFile; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # $Id: IniFile.pm,v 1.9 2005/03/17 14:58:00 sjn Exp $ | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( OpenInteract2::Config ); | ||||||||||||||||||
|
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::Config::Ini; | ||||||||||||||||||
|
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 | |||||||||||||||||||||
| 13 | 87 | $OpenInteract2::Config::IniFile::VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 87 | ▶ | use constant META_KEY => '_INI'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 87 | my $DEFAULT_READER = 'OpenInteract2::Config::Ini'; | |||||||||||||||||||
| 18 | 87 | my %REQUIRED = ( | |||||||||||||||||||
| 19 | 'OpenInteract2::Config::Ini' => 1, | ||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 87 | my ( $log ); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | ▶ | sub valid_keys { | ||||||||||||||||||
|
Subroutine
valid_keys: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 25 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 26 | #return $self->sections; | ||||||||||||||||||||
| 27 | #return grep ! /^_/, keys %{ $self }; | ||||||||||||||||||||
| 28 | 0 | return @{ $self->{_m}{order} }; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 16 | ▶ | sub read_config { | ||||||||||||||||||
|
Subroutine
read_config: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||
| 33 | 16 | my ( $class, $params ) = @_; | |||||||||||||||||||
| 34 | 16 | ▶ | $log ||= get_logger( LOG_CONFIG ); | ||||||||||||||||||
|
Condition66%2/3
$log ||= get_logger("OI2.CONFIG")
MC/DC0%0/2
$log ||= get_logger("OI2.CONFIG")
$log
get_logger("OI2.CONFIG")
Truth table66%2/3
A ||= B
A= $logB= get_logger("OI2.CONFIG")
| |||||||||||||||||||||
| 35 | 16 | ▶ | if ( $params->{filename} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 36 | 14 | $class->is_file_valid( $params->{filename} ); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | elsif ( ! $params->{content} ) { | ||||||||||||||||||||
| 39 | 0 | oi_error "No filename or content given for configuration data"; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 16 | my $reader_class = $class->_check_reader_class(); | |||||||||||||||||||
| 42 | 16 | my $ini = eval { | |||||||||||||||||||
| 43 | $reader_class->new({ content => $params->{content}, | ||||||||||||||||||||
| 44 | filename => $params->{filename} }) | ||||||||||||||||||||
| 45 | 16 | }; | |||||||||||||||||||
| 46 | 0 | ▶ | if ( $@ ) { oi_error $@ } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 16 | return $ini; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # Cheeseball, but it works | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub write_config { | ||||||||||||||||||
|
Subroutine
write_config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 54 | 0 | my ( $self, $filename ) = @_; | |||||||||||||||||||
| 55 | 0 | my $backup = $self; | |||||||||||||||||||
| 56 | 0 | my $bless_class = $self->_check_reader_class(); | |||||||||||||||||||
| 57 | 0 | bless( $backup, $bless_class ); | |||||||||||||||||||
| 58 | 0 | my $actual_filename = eval { $backup->write_file( $filename ) }; | |||||||||||||||||||
| 59 | 0 | ▶ | oi_error $@ if ( $@ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | return $actual_filename; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | sub ini_factory { | ||||||||||||||||||
|
Subroutine
ini_factory: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 65 | 0 | my ( $class ) = @_; | |||||||||||||||||||
| 66 | 0 | my $impl_class = $class->_check_reader_class(); | |||||||||||||||||||
| 67 | 0 | return $impl_class->new(); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 16 | ▶ | sub _check_reader_class { | ||||||||||||||||||
|
Subroutine
_check_reader_class: called CC=5 SCAR=27.4
| |||||||||||||||||||||
| 71 | 16 | my ( $class ) = @_; | |||||||||||||||||||
| 72 | 16 | ▶ | $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")
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 16 | ▶ | return $DEFAULT_READER unless ( CTX ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | my $reader_class = CTX->lookup_class( 'ini_reader' ); | |||||||||||||||||||
| 77 | 0 | ▶ | unless ( $REQUIRED{ $reader_class } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 0 | eval "require $reader_class"; | |||||||||||||||||||
| 79 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 0 | $log->error( "Cannot require '$reader_class'; will use ", | |||||||||||||||||||
| 81 | "default reader '$DEFAULT_READER' instead. ", | ||||||||||||||||||||
| 82 | "(Error: $@)" ); | ||||||||||||||||||||
| 83 | 0 | $reader_class = $DEFAULT_READER; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||
| 86 | 0 | $REQUIRED{ $reader_class }++; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 0 | return $reader_class; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 87 | 1; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||