Commit | Line | Data |
f0e3c221 |
1 | package MockApp; |
2 | use strict; |
3 | use warnings; |
4 | |
5 | $|++; |
6 | |
aa7bd7c3 |
7 | use Test::More tests => 14; |
f0e3c221 |
8 | use Scalar::Util qw(blessed reftype); |
9 | |
10 | use Config::Any; |
11 | use Config::Any::INI; |
12 | |
13 | our $cfg_file = 't/conf/conf.foo'; |
14 | |
92a04e78 |
15 | eval { Config::Any::INI->load( $cfg_file ); }; |
aa7bd7c3 |
16 | |
f0e3c221 |
17 | SKIP: { |
aa7bd7c3 |
18 | skip "File loading backend for INI not found", 14 if $@; |
19 | |
77f14cda |
20 | my $struct; # used to make sure parsing works for arrays and hashes |
f0e3c221 |
21 | |
aa7bd7c3 |
22 | # force_plugins |
23 | { |
24 | my $result = Config::Any->load_files( |
92a04e78 |
25 | { files => [ $cfg_file ], |
26 | force_plugins => [ qw(Config::Any::INI) ] |
27 | } |
aa7bd7c3 |
28 | ); |
f0e3c221 |
29 | |
aa7bd7c3 |
30 | ok( $result, 'load file with parser forced' ); |
f0e3c221 |
31 | |
aa7bd7c3 |
32 | ok( my $first = $result->[ 0 ], 'load_files returns an arrayref' ); |
33 | ok( ref $first, 'load_files arrayref contains a ref' ); |
f0e3c221 |
34 | |
aa7bd7c3 |
35 | my $ref = blessed $first ? reftype $first : ref $first; |
36 | is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); |
f0e3c221 |
37 | |
aa7bd7c3 |
38 | $struct = $first; |
92a04e78 |
39 | |
aa7bd7c3 |
40 | my ( $name, $cfg ) = %$first; |
41 | is( $name, $cfg_file, 'filenames match' ); |
92a04e78 |
42 | |
aa7bd7c3 |
43 | my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; |
44 | is( substr( $cfgref, 0, 4 ), 'HASH', 'hashref cfg' ); |
45 | |
46 | is( $cfg->{ name }, 'TestApp', 'appname parses' ); |
47 | is( $cfg->{ Component }{ "Controller::Foo" }->{ foo }, |
48 | 'bar', 'component->cntrlr->foo = bar' ); |
49 | is( $cfg->{ Model }{ "Model::Baz" }->{ qux }, |
50 | 'xyzzy', 'model->model::baz->qux = xyzzy' ); |
51 | } |
52 | |
53 | # flatten_to_hash |
54 | { |
55 | my $result = Config::Any->load_files( |
56 | { files => [ $cfg_file ], |
57 | force_plugins => [ qw(Config::Any::INI) ], |
58 | flatten_to_hash => 1 |
92a04e78 |
59 | } |
aa7bd7c3 |
60 | ); |
61 | |
dcfb1d1d |
62 | ok( $result, 'load file with parser forced, flatten to hash' ); |
aa7bd7c3 |
63 | ok( ref $result, 'load_files hashref contains a ref' ); |
64 | |
65 | my $ref = blessed $result ? reftype $result : ref $result; |
66 | is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); |
67 | |
77f14cda |
68 | is_deeply( $result, $struct, |
69 | 'load_files return an hashref (flatten_to_hash)' ); |
aa7bd7c3 |
70 | } |
77f14cda |
71 | |
72 | # use_ext |
aa7bd7c3 |
73 | { |
74 | ok( my $result = Config::Any->load_files( |
75 | { files => [ $cfg_file ], |
76 | force_plugins => [ qw(Config::Any::INI) ], |
77 | use_ext => 1 |
78 | } |
79 | ), |
80 | "load file with parser forced" |
81 | ); |
82 | } |
f0e3c221 |
83 | } |
84 | |