| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | $ARG eq 'ARRAY' and do { $files_ref = $file; last }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$cfany_hash and ref $cfany_hash and ref $cfany_hash eq "HASH"
$cfany_hash and ref $cfany_hash
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||