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