Commit | Line | Data |
f0e3c221 |
1 | package MockApp; |
2 | use strict; |
3 | use warnings; |
e7be073a |
4 | no warnings 'once'; |
f0e3c221 |
5 | |
6 | $|++; |
7 | use Test::More tests => 54; |
8 | use Scalar::Util qw(blessed reftype); |
9 | use Config::Any; |
10 | use Config::Any::General; |
11 | use Config::Any::INI; |
12 | use Config::Any::JSON; |
13 | use Config::Any::Perl; |
14 | use Config::Any::XML; |
15 | use Config::Any::YAML; |
16 | |
e7be073a |
17 | $Config::Any::YAML::NO_YAML_XS_WARNING = 1; |
18 | |
f0e3c221 |
19 | our %ext_map = ( |
20 | conf => 'Config::Any::General', |
21 | ini => 'Config::Any::INI', |
22 | json => 'Config::Any::JSON', |
23 | pl => 'Config::Any::Perl', |
24 | xml => 'Config::Any::XML', |
25 | yml => 'Config::Any::YAML' |
26 | ); |
27 | |
28 | sub load_parser_for { |
29 | my $f = shift; |
30 | return unless $f; |
31 | |
92a04e78 |
32 | my ( $ext ) = $f =~ m{ \. ( [^\.]+ ) \z }xms; |
33 | my $mod = $ext_map{ $ext }; |
d8d4d543 |
34 | return !$mod->is_supported ? ( 1, $mod ) : ( 0, $mod ); |
f0e3c221 |
35 | } |
36 | |
92a04e78 |
37 | for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) { |
38 | my ( $skip, $mod ) = load_parser_for( $f ); |
39 | SKIP: { |
f0e3c221 |
40 | skip "File loading backend for $mod not found", 9 if $skip; |
92a04e78 |
41 | |
42 | ok( my $c_arr |
43 | = Config::Any->load_files( |
44 | { files => [ $f ], use_ext => 1 } ), |
45 | "load_files with use_ext works [$f]" |
46 | ); |
47 | ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" ); |
48 | |
49 | ok( ref $c, "load_files arrayref contains a ref" ); |
f0e3c221 |
50 | my $ref = blessed $c ? reftype $c : ref $c; |
92a04e78 |
51 | is( substr( $ref, 0, 4 ), "HASH", "hashref" ); |
52 | |
53 | my ( $name, $cfg ) = each %$c; |
54 | is( $name, $f, "filename matches" ); |
f0e3c221 |
55 | |
f0e3c221 |
56 | my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; |
92a04e78 |
57 | is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" ); |
f0e3c221 |
58 | |
92a04e78 |
59 | is( $cfg->{ name }, 'TestApp', "appname parses" ); |
60 | is( $cfg->{ Component }{ "Controller::Foo" }->{ foo }, |
61 | 'bar', "component->cntrlr->foo = bar" ); |
62 | is( $cfg->{ Model }{ "Model::Baz" }->{ qux }, |
63 | 'xyzzy', "model->model::baz->qux = xyzzy" ); |
f0e3c221 |
64 | } |
65 | } |
66 | |