| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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
|
1
|
|
|
1
|
|
24491
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
59
|
|
|
10
|
1
|
|
|
1
|
|
13
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
58
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package MouseX::SimpleConfig; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
|
16
|
1
|
|
|
1
|
|
18
|
$MouseX::SimpleConfig::VERSION = '0.11'; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ABSTRACT: A Mouse role for setting attributes from a simple configfile |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
96
|
|
|
22
|
1
|
|
|
1
|
|
1080
|
use English '-no_match_vars'; |
|
|
1
|
|
|
|
|
4799
|
|
|
|
1
|
|
|
|
|
8
|
|
|
23
|
1
|
|
|
1
|
|
1542
|
use Mouse::Role; |
|
|
1
|
|
|
|
|
35970
|
|
|
|
1
|
|
|
|
|
7
|
|
|
24
|
|
|
|
|
|
|
with 'MouseX::ConfigFromFile'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
816
|
use Config::Any (); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_config_from_file { |
|
29
|
|
|
|
|
|
|
my ( $class, $file ) = @ARG; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $files_ref; |
|
32
|
|
|
|
|
|
|
for ( ref $file ) { |
|
33
|
|
|
|
|
|
|
$ARG eq 'CODE' and do { $file = $file->(); last }; |
|
34
|
|
|
|
|
|
|
$ARG eq 'ARRAY' and do { $files_ref = $file; last }; |
|
35
|
|
|
|
|
|
|
$files_ref = [$file]; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $can_config_any_args = $class->can('config_any_args'); |
|
39
|
|
|
|
|
|
|
my %cfany_args; |
|
40
|
|
|
|
|
|
|
if ($can_config_any_args) { |
|
41
|
|
|
|
|
|
|
%cfany_args = %{ $can_config_any_args->( $class, $file ) }; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
$cfany_args{use_ext} = 1; |
|
44
|
|
|
|
|
|
|
$cfany_args{files} = $files_ref; |
|
45
|
|
|
|
|
|
|
$cfany_args{flatten_to_hash} = 1; |
|
46
|
|
|
|
|
|
|
my $raw_cfany = Config::Any->load_files( \%cfany_args ); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my %raw_config; |
|
49
|
|
|
|
|
|
|
foreach my $file_tested ( reverse @{$files_ref} ) { |
|
50
|
|
|
|
|
|
|
if ( !exists $raw_cfany->{$file_tested} ) { |
|
51
|
|
|
|
|
|
|
warn qq{Specified configfile '$file_tested' does not exist, } |
|
52
|
|
|
|
|
|
|
. qq{is empty, or is not readable\n}; |
|
53
|
|
|
|
|
|
|
next; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $cfany_hash = $raw_cfany->{$file_tested}; |
|
57
|
|
|
|
|
|
|
croak |
|
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
|
|
|
|
|
|
|
%raw_config = ( %raw_config, %{$cfany_hash} ); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return \%raw_config; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
no Mouse::Role; |
|
70
|
|
|
|
|
|
|
1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |