lib/Ubic/ServiceLoader/Ext/ini.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 75.0% 9 / 12 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 93.1% 54 / 58 SCAR 20.8
CC
8
Cov
92%
load
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
« lib/Ubic/AtomicFile.pm ↑ Summary tfiles/service/multi-impl »
1 package Ubic::ServiceLoader::Ext::ini;
2 3 $Ubic::ServiceLoader::Ext::ini::VERSION = '1.59';
3 # ABSTRACT: loader for ini-style configs
4  
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use parent qw( Ubic::ServiceLoader::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 2 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 2 return bless {} => $class;
16 }
17  
18 sub load {
19 6 ▶ my $self = shift;
Subroutine load: called CC=8 SCAR=20.9
Pod documented
20 6 my ($file) = @_;
21  
22 6 my $config = Config::Tiny->read($file);
23 6 ▶ unless ($config) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config) 1 5 6
24 1 die Config::Tiny->errstr;
25 }
26  
27 5 my $root_section = delete $config->{_};
28 5 ▶ my $module = delete $root_section->{module} || 'Ubic::Service::SimpleDaemon';
Condition100%2/2
delete $root_section->{'module'} || 'Ubic::Service::SimpleDaemon'
l!l
41
MC/DC100%1/1
delete $root_section->{'module'} || 'Ubic::Service::SimpleDaemon'
delete $root_section->{'module'}
Truth table100%2/2
A
A= delete $root_section->{'module'}
Aresult
11
00
29 5 ▶ if (keys %$root_section) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$root_section) 1 4 5
30 1 die "Unknown option ".join(', ', keys %$root_section)." in file $file";
31 }
32  
33 4 my $options = delete $config->{options};
34 4 ▶ if (keys %$config) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$config) 1 3 4
35 1 die "Unknown section ".join(', ', keys %$config)." in file $file";
36 }
37  
38 3 ▶ $module =~ /^[\w:]+$/ or die "Invalid module name '$module'";
Branch: 1 branch
BranchTrueFalseTotal
$module =~ /^[\w:]+$/ or die "Invalid module name '${module}'" 0 3 3
39 3 eval "require $module"; # TODO - Class::Load?
40 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
41 0 die $@;
42 }
43  
44 3 my @options = ();
45 3 ▶ @options = ($options) if $options; # some modules can have zero options, I guess
Branch: 1 branch
BranchTrueFalseTotal
if $options 3 0 3
46 3 return $module->new(@options);
47 }
48  
49 3 1;
50  
51 __END__
« lib/Ubic/AtomicFile.pm ↑ Summary tfiles/service/multi-impl »