OpenInteract2/Config/IniFile.pm

filter: Statementstmt 63.0% 41 / 65 Branchbran 35.7% 5 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 4 totaltotal 55.6% 59 / 106 CC 10 SCAR 17.7
CC
10
Cov
58%
_check_reader_class
15.5
write_config
6.0
read_config
5.4
CRAP 5.8
« OpenInteract2/ParamContainer.pm ↑ Summary OpenInteract2/Upload.pm »
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")
l!l&&r!l&&!r
1150
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")
ABresult
1X1
011
000
35 16 ▶ if ( $params->{filename} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'filename'}) { } 14 2 16
elsif (not $params->{'content'}) { } 0 2 2
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
BranchTrueFalseTotal
if ($@) 0 16 16
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
BranchTrueFalseTotal
if $@ 0 0 0
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")
l!l&&r!l&&!r
1600
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")
ABresult
1X1
011
000
73  
74 16 ▶ return $DEFAULT_READER unless ( CTX );
Branch: 1 branch
BranchTrueFalseTotal
unless CTX() 16 0 16
75  
76 0 my $reader_class = CTX->lookup_class( 'ini_reader' );
77 0 ▶ unless ( $REQUIRED{ $reader_class } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($REQUIRED{$reader_class}) 0 0 0
78 0 eval "require $reader_class";
79 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
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__
« OpenInteract2/ParamContainer.pm ↑ Summary OpenInteract2/Upload.pm »