| 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
| |||||||||||||
| 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'
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'}
| |||||||||||||
| 29 | 5 | ▶ | if (keys %$root_section) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 39 | 3 | eval "require $module"; # TODO - Class::Load? | |||||||||||
| 40 | 3 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 46 | 3 | return $module->new(@options); | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 3 | 1; | |||||||||||
| 50 | |||||||||||||
| 51 | __END__ | ||||||||||||