blib/lib/MouseX/SimpleConfig.pm

filter: Statementstmt 89.2% 50 / 56 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 80.2% 69 / 86 CC 10 SCAR 19.8
CC
10
Cov
81%
get_config_from_file
12.8
BEGIN
1.0
BEGIN
1.0
CRAP 7.2
↑ Summary
1 #
2 # This file is part of MouseX-SimpleConfig
3 #
4 # This software is copyright (c) 2011 by Infinity Interactive.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package MouseX::SimpleConfig;
14  
15 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 $MouseX::SimpleConfig::VERSION = '0.11';
17 }
18  
19 # ABSTRACT: A Mouse role for setting attributes from a simple configfile
20  
21 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use English '-no_match_vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use Mouse::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 with 'MouseX::ConfigFromFile';
25  
26 4 ▶use Config::Any ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 4 ▶sub get_config_from_file {
Subroutine get_config_from_file: called CC=10 SCAR=25.5
Pod documented
29 4 my ( $class, $file ) = @ARG;
30  
31 4 my $files_ref;
32 4 for ( ref $file ) {
33 0 ▶ $ARG eq 'CODE' and do { $file = $file->(); last };
Branch: 1 branch
BranchTrueFalseTotal
$MouseX::SimpleConfig::ARG eq "CODE" and do { $file = &$file(); last } 0 4 4
34 4 ▶ $ARG eq 'ARRAY' and do { $files_ref = $file; last };
Branch: 1 branch
BranchTrueFalseTotal
$MouseX::SimpleConfig::ARG eq "ARRAY" and do { $files_ref = $file; last } 2 2 4
35 2 $files_ref = [$file];
36 }
37  
38 4 my $can_config_any_args = $class->can('config_any_args');
39 4 my %cfany_args;
40 4 ▶ if ($can_config_any_args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_config_any_args) 0 4 4
41 0 %cfany_args = %{ $can_config_any_args->( $class, $file ) };
42 }
43 4 $cfany_args{use_ext} = 1;
44 4 $cfany_args{files} = $files_ref;
45 4 $cfany_args{flatten_to_hash} = 1;
46 4 my $raw_cfany = Config::Any->load_files( \%cfany_args );
47  
48 4 my %raw_config;
49 4 foreach my $file_tested ( reverse @{$files_ref} ) {
50 5 ▶ if ( !exists $raw_cfany->{$file_tested} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $raw_cfany->{$file_tested}) 0 5 5
51 0 warn qq{Specified configfile '$file_tested' does not exist, }
52 . qq{is empty, or is not readable\n};
53 0 next;
54 }
55  
56 5 my $cfany_hash = $raw_cfany->{$file_tested};
57 5 ▶ croak
Branch: 1 branch
BranchTrueFalseTotal
unless $cfany_hash and ref $cfany_hash and ref $cfany_hash eq "HASH" 0 5 5
Condition33%2/6
$cfany_hash and ref $cfany_hash and ref $cfany_hash eq "HASH"
!ll&&!rl&&r
005
$cfany_hash and ref $cfany_hash
!ll&&!rl&&r
005
MC/DC0%0/3
$cfany_hash and ref $cfany_hash and ref $cfany_hash eq "HASH"
$cfany_hash ref $cfany_hash ref $cfany_hash eq "HASH"
Truth table25%1/4
A and B and C
A= $cfany_hashB= ref $cfany_hashC= ref $cfany_hash eq "HASH"
ABCresult
0XX0
10X0
1100
1111
58 "configfile must represent a hash structure in file: $file_tested"
59 if not( $cfany_hash
60 && ref $cfany_hash
61 && ref $cfany_hash eq 'HASH' );
62  
63 5 %raw_config = ( %raw_config, %{$cfany_hash} );
64 }
65  
66 4 return \%raw_config;
67 }
68  
69 4 ▶no Mouse::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 4 1;
71  
72 __END__
↑ Summary