refactor _load(). fix an issue with use_ext => 0. use_ext now on by default. throw...
[p5sagit/Config-Any.git] / t / 61-features.t
CommitLineData
f0e3c221 1package MockApp;
2use strict;
3use warnings;
4
5$|++;
6
7use Test::More tests => 10;
8use Scalar::Util qw(blessed reftype);
9
10use Config::Any;
11use Config::Any::INI;
12
13our $cfg_file = 't/conf/conf.foo';
14
92a04e78 15eval { Config::Any::INI->load( $cfg_file ); };
f0e3c221 16SKIP: {
17 skip "File loading backend for INI not found", 10 if $@;
18
92a04e78 19 ok( my $c_arr = Config::Any->load_files(
20 { files => [ $cfg_file ],
21 force_plugins => [ qw(Config::Any::INI) ]
22 }
23 ),
24 "load file with parser forced"
25 );
f0e3c221 26
92a04e78 27 ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" );
f0e3c221 28
92a04e78 29 ok( ref $c, "load_files arrayref contains a ref" );
30 my $ref = blessed $c ? reftype $c : ref $c;
31 is( substr( $ref, 0, 4 ), "HASH", "hashref" );
f0e3c221 32
92a04e78 33 my ( $name, $cfg ) = each %$c;
34 is( $name, $cfg_file, "filename matches" );
f0e3c221 35
92a04e78 36 my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg;
37 is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" );
38
39 is( $cfg->{ name }, 'TestApp', "appname parses" );
40 is( $cfg->{ Component }{ "Controller::Foo" }->{ foo },
41 'bar', "component->cntrlr->foo = bar" );
42 is( $cfg->{ Model }{ "Model::Baz" }->{ qux },
43 'xyzzy', "model->model::baz->qux = xyzzy" );
44
45 ok( my $c_arr_2 = Config::Any->load_files(
46 { files => [ $cfg_file ],
47 force_plugins => [ qw(Config::Any::INI) ],
48 use_ext => 1
49 }
50 ),
51 "load file with parser forced"
52 );
f0e3c221 53}
54