Simple.pm

filter: Statementstmt 82.0% 32 / 39 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 76.9% 50 / 65 CC 8 SCAR 12.1
CC
8
Cov
76%
config
5.4
config_file
3.7
_check_hashref
2.5
CRAP 3.4
« Simple/YAML.pm ↑ Summary
1 package Config::Files::Simple;
2  
3 =encoding UTF-8
4
5 =head1 NAME
6
7 Config::Files::Simple - Yet another config file reader.
8  
9 =head1 VERSION
10  
11 version 0.03
12  
13 =cut
14  
15 3 our $VERSION = '0.03'; # VERSION
16  
17 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use vars qw/$VERSION @EXPORT_OK/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 require Exporter;
22 3 *import = \&Exporter::import;
23 3 @EXPORT_OK = qw( config config_file);
24 3 our $_hr_config;
25  
26 =head1 EXPORT
27  
28 =over 4
29  
30 =item * config
31  
32 =back
33  
34 =head1 SUBROUTINES/METHODS
35  
36 =head2 config
37  
38 Read configuration file from current path.
39 It needs a YAML file.
40  
41 =cut
42  
43 3 ▶sub config {
Subroutine config: called CC=5 SCAR=16.8
Pod documented
44 3 ▶ $_hr_config = _check_hashref( $_[0] ) if ( $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 1 2 3
45 3 ▶ return $_hr_config if $_hr_config;
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Files::Simple::_hr_config 2 1 3
46 1 ▶ if ( -f 'config.yaml' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f 'config.yaml') { } 0 1 1
elsif (-f 'config.yml') { } 0 1 1
47 0 return config_file( 'config.yaml', 'YAML' );
48 }
49 elsif ( -f 'config.yml' ) {
50 0 return config_file( 'config.yml', 'YAML' );
51 }
52 else {
53 1 require Carp;
54 1 Carp::cluck('could not find a config.yml or config.yaml file');
55 1 die;
56 }
57 }
58  
59 =head2 config_file
60  
61 Read configuration file from given path.
62  
63 =cut
64  
65 2 ▶sub config_file {
Subroutine config_file: called CC=3 SCAR=13.1
Pod documented
66 2 ▶ if ( -f $_[0] && defined $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $_[0] and defined $_[1]) { } 2 0 2
Condition33%1/3
-f $_[0] and defined $_[1]
!ll&&!rl&&r
002
MC/DC0%0/2
-f $_[0] and defined $_[1]
-f $_[0] defined $_[1]
Truth table33%1/3
A and B
A= -f $_[0]B= defined $_[1]
ABresult
0X0
100
111
67 2 require Module::Load;
68 2 my $loading_package = "Config::Files::Simple::$_[1]";
69 2 Module::Load::load $loading_package;
70 2 $_hr_config = _check_hashref( $loading_package->new->config_file( $_[0] ) );
71 2 return $_hr_config;
72 }
73 else {
74 0 require Carp;
75 0 Carp::cluck("could not find $_[0] file");
76 }
77 0 return undef;
78 }
79  
80 =head2 _check_hashref
81  
82 private hashref checking sub
83  
84 =cut
85  
86 3 ▶sub _check_hashref {
Subroutine _check_hashref: called CC=2 SCAR=9.2
87 3 require Ref::Util;
88 3 ▶ return $_[0] if ( Ref::Util::is_hashref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::is_hashref($_[0]) 3 0 3
89 0 require Carp;
90 0 Carp::cluck('config data must be a hashref');
91 }
92  
93 3 1;
94  
95 __END__
« Simple/YAML.pm ↑ Summary