YAML-AppConfig-0.19/0000755000175000017500000000000012310536176013135 5ustar grozngroznYAML-AppConfig-0.19/t/0000755000175000017500000000000012310536176013400 5ustar grozngroznYAML-AppConfig-0.19/t/03-vars.t0000644000175000017500000001450612310054525014757 0ustar grozngroznuse strict; use warnings; use Test::More tests => 56; do "t/lib/helpers.pl"; use Storable qw(dclone); BEGIN { use_ok('YAML::AppConfig') } # TEST: Variable usage. { my $app = YAML::AppConfig->new( file => 't/data/vars.yaml' ); ok($app, "Created object."); # Check basic retrieval is( $app->get_dapper, "life", "Checking variables." ); is( $app->get_breezy, "life is good", "Checking variables." ); is( $app->get_hoary, "life is good, but so is food", "Checking variables." ); is( $app->get_stable, "life is good, but so is food and so, once again, life is good.", "Checking variables." ); is( $app->get_nonvar, '$these are $non $vars with a var, life', "Checking variables." ); # Check get()'s no resolve flag is( $app->get( 'breezy', 1 ), '$dapper is good', "Checking variables, no resolve." ); is( $app->get_hoary(1), '$breezy, but so is food', "Checking variables, no resolve." ); # Check basic setting $app->set_dapper("money"); is( $app->get_dapper, "money", "Checking variables." ); is( $app->get_breezy, "money is good", "Checking variables." ); is( $app->get_hoary, "money is good, but so is food", "Checking variables." ); is( $app->get_stable, "money is good, but so is food and so, once again, money is good.", "Checking variables." ); is( $app->get_nonvar, '$these are $non $vars with a var, money', "Checking variables." ); # Check that our circular references break. for my $n ( 1 .. 4 ) { my $method = "get_circ$n"; eval { $app->$method }; like( $@, qr/Circular reference/, "Checking that get_circ$n failed" ); } # Break the circular reference. $app->set_circ1("dogs"); is($app->get_circ1, "dogs", "Checking circularity removal."); is($app->get_circ2, "dogs lop bop oop", "Checking circularity removal."); is($app->get_circ3, "dogs lop bop", "Checking circularity removal."); is($app->get_circ4, "dogs lop", "Checking circularity removal."); # Test that we references load up in the expected way within scalars. like( $app->get_refs, qr/^ARRAY\(.*?\) will not render, nor will HASH\(.*?\)$/, "Checking that references are not used as variables." ); # Test that nesting and interpolation of references works my $nestee = { food => 'money', drink => [{ cows => [qw(are good)]}, "money is good and moneyyummy"], }; is_deeply( $app->get_nest1, { blah => ["harry potter", "golem", "mickey mouse", $nestee], loop => {foopy => [$nestee, "money is good"], boop => $nestee}, }, "Checking variable interpolation with references." ); # Make sure circular references between references breaks eval { $app->get_circrefref1 }; like( $@, qr/Circular reference/, "Checking that get_circreref1 failed" ); # Look in the heart of our deep data structures is_deeply($app->get_list, [[[[[[[ [ 'money', "money is good, but so is food and so, once again, money is good.", ], "money is good, but so is food" ]]]]]]], "Testing nested list."); is_deeply( $app->get_hash, { key => { key => { key => { key => { key => 'money is good', other => 'money' }, something => 'money' } } } }, "Testing nested hash." ); } # TEST: no_resolve { my $app = YAML::AppConfig->new( file => 't/data/vars.yaml', no_resolve => 1 ); ok($app, "Created object."); # Check basic retrieval is( $app->get_dapper, "life", "Checking variables, no_resolve => 1" ); is( $app->get_breezy, '$dapper is good', "Checking variables, no_resolve => 1" ); is( $app->get_hoary, '$breezy, but so is food', "Checking variables, no_resolve => 1" ); is( $app->get_stable, '$hoary and so, once again, $breezy.', "Checking variables, no_resolve => 1" ); is( $app->get_nonvar, '$these are $non $vars with a var, $dapper', "Checking variables, no_resolve => 1" ); } # TEST: Substituting in a variable with no value does not produce warnings { my $app = YAML::AppConfig->new( string => "---\nnv:\nfoo: \$nv bar\n" ); ok($app, "Object created"); local $SIG{__WARN__} = sub { die }; eval { $app->get_nv }; ok( !$@, "Getting a setting with no value does not produce warnings." ); eval { $app->get_foo }; ok( !$@, "Getting a setting using a no value variable does not warn." ); is( $app->get_foo, " bar", "No value var used as empty string." ); } # TEST: Make sure ${foo} style vars work. { my $yaml =<<'YAML'; --- xyz: foo xyzbar: bad '{xyzbar': bad 'xyz}bar': bad test1: ${xyz}bar test2: ${xyzbar test3: $xyz}bar YAML my $app = YAML::AppConfig->new( string => $yaml ); ok($app, "Object created"); is( $app->get_test1, 'foobar', "Testing \${foo} type variables." ); is( $app->get_test2, '${xyzbar', "Testing \${foo} type variables." ); is( $app->get_test3, 'foo}bar', "Testing \${foo} type variables." ); } # TEST: Escaping of variables. { my $yaml =<<'YAML'; --- paulv: likes cheese nosubst: \$paulv a lot usens: $nosubst \$paulv $paulv \\\$paulv \\$paulv cows. YAML my $ESCAPE_N = 10; # Add \\$paulv, \\\$paulv, \\\\$paulv, ... for my $n (1 .. $ESCAPE_N) { $yaml .= "literal$n: " . '\\'x$n . "\\\$paulv stuffs\n"; } my $app = YAML::AppConfig->new( string => $yaml ); ok($app, "Object created"); for my $n (1 .. $ESCAPE_N) { my $string = '\\'x$n . '$paulv stuffs'; is( $app->get("literal$n"), $string, "Testing escapes: $string" ); } is( $app->get_usens, '$paulv a lot $paulv likes cheese \\\\$paulv \\$paulv cows.', "Testing vars with escapes." ); } # TEST: self-circular references { my $yaml = <<'YAML'; --- foo: $foo bar: - cows - $bar YAML my $app = YAML::AppConfig->new( string => $yaml ); ok( $app, "Object loaded" ); eval { $app->get_foo }; like( $@, qr/Circular reference/, "Testing self-circular references. " ); eval { $app->get_bar }; like( $@, qr/Circular reference/, "Testing self-circular references. " ); } YAML-AppConfig-0.19/t/04-api.t0000644000175000017500000000520012310054525014545 0ustar grozngroznuse strict; use warnings; use Test::More tests => 24; do "t/lib/helpers.pl"; BEGIN { use_ok('YAML::AppConfig') } # TEST: config and config_keys { my $app = YAML::AppConfig->new( file => 't/data/config.yaml' ); ok( $app, "Object created." ); is_deeply( $app->config, { foo => 1, bar => 2, eep => '$foo' }, "config() method." ); is_deeply( [ $app->config_keys ], [qw(bar eep foo)], "config_keys() method." ); } # TEST: merge { my $app = YAML::AppConfig->new( file => 't/data/basic.yaml' ); ok( $app, "Object created." ); is( $app->get_foo, 1, "Checking foo before merge()." ); is( $app->get_bar, 2, "Checking bar before merge()." ); $app->merge( file => 't/data/merge.yaml' ); is( $app->get_foo, 2, "Checking foo after merge()." ); is( $app->get_bar, 2, "Checking bar after merge()." ); is( $app->get_baz, 3, "Checking bar after merge()." ); } # TEST: resolve { my $yaml = <<'YAML'; --- foo: hello bar: $foo world circ1: $circ2 circ2: $circ1 cows: - are - wonderful - $bar YAML my $app = YAML::AppConfig->new( string => $yaml ); ok($app, "Object loaded"); is( $app->resolve('I like $bar a lot'), 'I like hello world a lot', 'Testing our resolve()' ); is_deeply( $app->resolve('$cows'), [qw(are wonderful), "hello world"], 'Testing our resolve() with references', ); eval { $app->resolve('$circ1 is a loop!') }; like( $@, qr/Circular reference/, 'Testing our resolve() with circular refs' ); my $template = { qux => '$foo is good', baz => [ '$foo', '$cows' ] }; my $new = $app->resolve($template); isnt( $new, $template, "Testing we did not smash our old object" ); is_deeply( $new, { qux => 'hello is good', baz => [ 'hello', [ qw(are wonderful), "hello world" ], ], }, "Testing our resolve() with nested structures." ); } # TEST: dump { my $yaml = "---\nfoo: 1\nbar: 2\n"; my $app = YAML::AppConfig->new( string => $yaml ); ok( $app, "Object created." ); $app->set_foo(42); my $dump = $app->dump(); like( $dump, qr/foo:\s*42/, "Testing dump()" ); like( $dump, qr/bar:\s*2/, "Testing dump()" ); my $file = 't/data/dump.yaml'; $app->dump($file); ok( ( -f $file ), "Testing dump() with file: $file" ); ok( open( FILE, $file ), "Opening file: $file" ); my $text = join( "", ); like( $text, qr/foo:\s*42/, "Testing dump() with file: $file" ); like( $text, qr/bar:\s*2/, "Testing dump() with file: $file" ); is( $text, $dump, "Testing that dump() and dump() to file are same" ); } YAML-AppConfig-0.19/t/05-scoping.t0000644000175000017500000000321212310531605015437 0ustar grozngroznuse strict; use warnings; use Test::More tests => 9; do "t/lib/helpers.pl"; use Storable qw(dclone); BEGIN { use_ok('YAML::AppConfig') } # TEST: Testing dynamically scoped variables { my $app = YAML::AppConfig->new( file => 't/data/scoping.yaml' ); ok( $app, "Created object." ); is( $app->get_foo, "top scope", "Testing foo's value" ); is_deeply( $app->get_bar, { qux => "top scope" }, "Testing top scope." ); is_deeply( $app->get_baz, { foo => 'baz scope', qux => 'baz scope qux', test => 'world', quxx => [ { food => { burger => 'baz scope', test => 'world' }, fries => 'baz scope qux', test => 'world', }, { foo => 'inner scope', food => { burger => 'inner scope', test => 'world' }, fries => 'inner scope qux', test => 'world', }, ], }, "Testing big baz structure." ); is_deeply( $app->get_blah, { blah => "self ref test", ego => "self ref test" }, "Dynamic scoping handles self-refs right." ); eval {$app->get_simple_circ}; like( $@, qr/Circular reference in simple_circ/, "Checking circular dynamic variables." ); eval {$app->get_circ}; like( $@, qr/Circular reference in (?:prolog|circ|cows_are_good)/, "Checking circular dynamic variables." ); eval {$app->get_bigcirc}; like( $@, qr/Circular reference in thing/, "Checking circular dynamic variables." ); } YAML-AppConfig-0.19/t/lib/0000755000175000017500000000000012310536176014146 5ustar grozngroznYAML-AppConfig-0.19/t/lib/MatthewTestClass.pm0000644000175000017500000000017012310054525017732 0ustar grozngroznpackage MatthewTestClass; sub LoadFile { return {file => shift}; } sub Load { return {string => shift}; } 1; YAML-AppConfig-0.19/t/lib/helpers.pl0000644000175000017500000000021012310054525016127 0ustar grozngroznsub slurp { my $file = shift; local $/ = undef; open my $fh, $file or die "Could not open $file: $!\n"; return <$fh>; } YAML-AppConfig-0.19/t/data/0000755000175000017500000000000012310536176014311 5ustar grozngroznYAML-AppConfig-0.19/t/data/merge.yaml0000644000175000017500000000006112310054525016262 0ustar grozngrozn--- # To be merged with basic.yaml foo: 2 baz: 3 YAML-AppConfig-0.19/t/data/basic.yaml0000644000175000017500000000002212310054525016241 0ustar grozngrozn--- foo: 1 bar: 2 YAML-AppConfig-0.19/t/data/config.yaml0000644000175000017500000000003412310054525016430 0ustar grozngrozn--- foo: 1 bar: 2 eep: $foo YAML-AppConfig-0.19/t/data/vars.yaml0000644000175000017500000000210612310054525016140 0ustar grozngrozn--- dapper: life breezy: $dapper is good hoary: $breezy, but so is food stable: $hoary and so, once again, $breezy. nonvar: $these are $non $vars with a var, $dapper circ1: $circ2 eep circ2: $circ3 oop circ3: $circ4 bop circ4: $circ1 lop refs: $list will not render, nor will $hash list: - - - - - - - - $dapper - $stable - $hoary hash: key: key: key: key: key: $breezy other: $dapper something: $dapper nest1: blah: - harry potter - golem - mickey mouse - $nestee loop: foopy: - $nestee - $breezy boop: $nestee nest2: cows: - are - good nestee: food: $dapper drink: - $nest2 - $breezy and ${dapper}yummy circrefref1: - $circrefref2 circrefref2: - $circrefref1 YAML-AppConfig-0.19/t/data/scoping.yaml0000644000175000017500000000131712310062646016635 0ustar grozngrozn--- foo: top scope hello: world bar: qux: $foo blah: blah: self ref test ego: $blah circ: circ: $prolog prolog: $cows_are_good cows_are_good: $circ simple_circ: simple_circ: $simple_circ bigcirc: thing: $level3 level1: level2: level3: level4: level5: $thing baz: foo: baz scope qux: $foo qux test: $hello quxx: - food: burger: $foo test: $hello fries: $qux test: $hello - foo: inner scope food: burger: $foo test: $hello fries: $qux test: $hello YAML-AppConfig-0.19/t/data/normal.yaml0000644000175000017500000000034112310054525016454 0ustar grozngrozn--- food: oh man: yeah good: it is: good i_like: - tofu - spatetee - ice cream and: yummy: stuff like: popcorn or: - candy - fruit - bars 'somtin!^^^wild': cows '12_foo': blah YAML-AppConfig-0.19/t/00-load.t0000644000175000017500000000326612310054525014721 0ustar grozngroznuse strict; use warnings; use Test::More tests => 28; do "t/lib/helpers.pl"; use lib 't/lib'; BEGIN { use_ok('YAML::AppConfig') } my $SKIP_NUM = 0; test_load("YAML"); test_load("YAML::Syck"); ok($SKIP_NUM < 2, "Asserting at least one YAML parser was tested"); sub test_load { my $class = shift; SKIP: { delete $INC{'YAML/Syck.pm'}; delete $INC{'YAML.pm'}; eval "require $class; 0;"; if ($@) { $SKIP_NUM++; skip "$class did not load, this might be ok.", 13 } else { ok(1, "Testing $class"); } # TEST: Object creation { my $app = YAML::AppConfig->new(); ok($app, "Instantiated object"); is($app->{yaml_class}, $class, "Testing class is right."); isa_ok( $app, "YAML::AppConfig", "Asserting isa YAML::AppConfig" ); ok( $app->can('new'), "\$app has new() method." ); } # TEST: Loading a different YAML class, string. { my $test_class = 'MatthewTestClass'; my $app = YAML::AppConfig->new(string => "cows", yaml_class => $test_class); ok($app, "Instantiated object"); is($app->{yaml_class}, $test_class, "Testing class is right."); isa_ok( $app, "YAML::AppConfig", "Asserting isa YAML::AppConfig." ); is($app->get_string, "cows", "Testing alternate YAML class (stirng)."); } # TEST: Loading a different YAML class, file. { my $test_class = 'MatthewTestClass'; my $app = YAML::AppConfig->new(file => "dogs", yaml_class => $test_class); ok($app, "Instantiated object"); is($app->{yaml_class}, $test_class, "Testing class is right."); isa_ok( $app, "YAML::AppConfig", "Asserting isa YAML::AppConfig." ); is($app->get_file, "dogs", "Testing alternate YAML class (file)."); } } # end SKIP } # end SUB YAML-AppConfig-0.19/t/02-normal.t0000644000175000017500000000616612310054525015276 0ustar grozngroznuse strict; use warnings; use Test::More tests => 106; do "t/lib/helpers.pl"; BEGIN { use_ok('YAML::AppConfig') } # TEST: Object creation from a file, string, and object. { test_object_creation( string => slurp("t/data/normal.yaml") ); my $app = test_object_creation( file => "t/data/normal.yaml" ); test_object_creation( object => $app ); } sub test_object_creation { my $app = YAML::AppConfig->new( @_ ); ok( $app, "Checking object creation." ); # Test obvious accessors are there. for my $method (qw(food man good is i_like and)) { ok( $app->can("get_$method"), "Testing $method getter" ); ok( $app->can("set_$method"), "Testing $method setter" ); } # Test we didn't get some strays. for my $not_method (qw(yummy like or)) { ok( !$app->can("get_$not_method"), "Testing !$not_method getter" ); ok( !$app->can("set_$not_method"), "Testing !$not_method getter" ); } # Test our wild things ok( !$app->can('get_somtin!^^^wild'), "Checking we can't do get_somtin!^^^wild" ); ok( !$app->can('set_somtin!^^^wild'), "Checking we can't do set_somtin!^^^wild" ); is( $app->get('somtin!^^^wild'), 'cows', "Retrieving somtin!^^^wild" ); ok( !$app->can('get_12_foo'), "Checking we can't do get_12_foo" ); ok( !$app->can('set_12_foo'), "Checking we can't do set_12_foo" ); is( $app->get('12_foo'), 'blah', "Retrieving 12_foo" ); # Test the values is( $app->get_food, 'oh', "food test" ); is( $app->get_man, 'yeah', "man test" ); is( $app->get_good, 'it', "good test" ); is( $app->get_is, 'good', "is test" ); is_deeply( $app->get_i_like, [ 'tofu', 'spatetee', 'ice cream' ], "i_like test" ); is_deeply( $app->get_and, { yummy => 'stuff', like => 'popcorn', 'or' => [qw(candy fruit bars)] }, "and test" ); return $app; } # TEST: Two objects don't clober each others methods. { my $bar = "get_bar"; my $app1 = YAML::AppConfig->new( string => "---\nfoo: 1\nbar: 2\n" ); ok( $app1, "Checking object creation." ); ok( $app1->can("get_foo"), "Checking that \$app1 has get_foo method." ); ok( $app1->can("get_bar"), "Checking that \$app1 has get_bar method." ); is( $app1->$bar, 2, "Checking bar1 is ok." ); my $app2 = YAML::AppConfig->new( string => "---\nqux: 3\nbar: 5\n" ); ok( $app2, "Checking object creation." ); ok( $app2->can("get_qux"), "Checking that \$app2 has get_qux method." ); ok( $app2->can("get_bar"), "Checking that \$app2 has get_bar method." ); is( $app2->$bar, 5, "Checking bar2 is ok." ); # Make sure we didn't clober each other. is( $app1->$bar, 2, "Checking that value of bar1 in app1 is the same." ); is( $app2->$bar, 5, "Checking that value of bar2 in app1 is the same." ); } # TEST: Make sure we don't get warnings on undef. values { my $app = YAML::AppConfig->new( string => "---\nnovalue:\n" ); ok($app, "Object created"); local $SIG{__WARN__} = sub { die }; eval { $app->get_novalue }; ok( !$@, "Getting a setting with no value does not produce warnings." ); } YAML-AppConfig-0.19/t/01-basic.t0000644000175000017500000000301712310367007015060 0ustar grozngroznuse strict; use warnings; use Test::More tests => 21; do "t/lib/helpers.pl"; BEGIN { use_ok('YAML::AppConfig') } # TEST: Object creation from a file. { my $app = YAML::AppConfig->new( file => "t/data/basic.yaml" ); ok( $app, "Instantiated object from file." ); isa_ok( $app, "YAML::AppConfig", "Asserting isa YAML::AppConfig" ); my $c = 1; for my $var (qw(foo bar)) { is( $app->get($var), $c, "Retrieving value for $var." ); my $method = "get_$var"; ok( $app->can($method), "Checking that \$app can get_$var." ); is( $app->$method($var), $c, "Retrieving $var with $method." ); $c++; } $app->set("bar", 99); is($app->get("bar"), 99, "Setting bar, type set()."); $app->set_bar(101); is( $app->get("bar"), 101, "Setting bar, type set_bar()." ); } # TEST: Object creation from string. { my $app = YAML::AppConfig->new( string => slurp("t/data/basic.yaml") ); ok( $app, "Instantiated object from string." ); isa_ok( $app, "YAML::AppConfig", "Asserting isa YAML::AppConfig" ); my $c = 1; for my $var (qw(foo bar)) { is( $app->get($var), $c, "Retrieving value for $var." ); my $method = "get_$var"; ok( $app->can($method), "Checking that \$app can get_$var." ); is( $app->$method($var), $c, "Retrieving $var with $method." ); $c++; } $app->set("bar", 99); is($app->get("bar"), 99, "Setting bar, type set()."); $app->set_bar(101); is( $app->get("bar"), 101, "Setting bar, type set_bar()." ); } YAML-AppConfig-0.19/LICENSE0000644000175000017500000004340312310367007014141 0ustar grozngroznThis is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End YAML-AppConfig-0.19/Changes0000644000175000017500000000225712310536000014420 0ustar grozngroznRevision history for Perl module YAML::AppConfig Development XAERXESS 0.19 2014-03-14T09:00:00+0100 XAERXESS [ Bug fixes ] - fixed hash randomization problem in test (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711627#19 by Csillag Tamas ) - META.{yaml,json} were missing prereqs [ Other changes ] - included missing README file - cleaned up prereqs 0.18 2014-03-13T19:00:00+0100 XAERXESS [ Bug fixes ] - fixed POD warning (RT #68118 by Damyan Ivanov ) - used ref instead of isa (RT #65539 by Guillaume Rousse ) [ Other changes ] - updated revision history in Changes (as per CPAN::Changes::Spec) - cleaned up documentation - tweaked Makefile.PL - included LICENSE file 0.17 2014-03-12T15:21:11+0100 XAERXESS - Grzegorz Rożniecki (XAERXESS) has taken over maintenance - fixed deprecated use of `for qw(...)` (RT #85987 by gregor herrmann ) - skipped test failing under Perl 5.18+ 0.16 2006-07-09 - released by Matthew O'Connor 0.14 2006-06-25 - released by Matthew O'Connor 0.12 2006-06-22 - released by Matthew O'Connor 0.10 2006-06-22 - first public version on CPAN YAML-AppConfig-0.19/MANIFEST0000644000175000017500000000071712310536176014273 0ustar grozngroznChanges lib/YAML/AppConfig.pm LICENSE Makefile.PL MANIFEST README.md t/00-load.t t/01-basic.t t/02-normal.t t/03-vars.t t/04-api.t t/05-scoping.t t/data/basic.yaml t/data/config.yaml t/data/merge.yaml t/data/normal.yaml t/data/scoping.yaml t/data/vars.yaml t/lib/helpers.pl t/lib/MatthewTestClass.pm META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) YAML-AppConfig-0.19/lib/0000755000175000017500000000000012310536176013703 5ustar grozngroznYAML-AppConfig-0.19/lib/YAML/0000755000175000017500000000000012310536176014445 5ustar grozngroznYAML-AppConfig-0.19/lib/YAML/AppConfig.pm0000644000175000017500000004564412310534576016670 0ustar grozngroznpackage YAML::AppConfig; use strict; use warnings; use Carp; use Storable qw(dclone); # For Deep Copy #################### # Global Variables #################### our $VERSION = '0.19'; our @YAML_PREFS = qw(YAML::Syck YAML); ######################### # Class Methods: Public ######################### sub new { my ($class, %args) = @_; my $self = bless( \%args, ref($class) || $class ); # Load a YAML parser. $self->{yaml_class} = $self->_load_yaml_class(); # Load config from file, string, or object. if ( exists $self->{file} ) { my $load_file = eval "\\&$self->{yaml_class}::LoadFile"; $self->{config} = $load_file->( $self->{file} ); } elsif ( exists $self->{string} ) { my $load = eval "\\&$self->{yaml_class}::Load"; $self->{config} = $load->( $self->{string} ); } elsif ( exists $self->{object} ) { $self->{config} = dclone( $self->{object}->{config} ); } else { $self->{config} = {}; } # Initialize internal state $self->_install_accessors(); # Install convenience accessors. $self->{seen} = {}; # For finding circular references. $self->{scope_stack} = []; # For implementing dynamic variables. return $self; } ############################# # Instance Methods: Public ############################# sub config { my $self = shift; return $self->{config}; } sub config_keys { my $self = shift; return sort keys %{$self->config}; } sub get { my $self = shift; $self->{seen} = {}; # Don't know if we exited cleanly, so clean up. return $self->_get(@_); } # Inner get so we can clear the seen hash above. Listed here for readability. sub _get { my ( $self, $key, $no_resolve ) = @_; return unless $self->_scope_has($key); return $self->config->{$key} if $self->{no_resolve} or $no_resolve; croak "Circular reference in $key." if exists $self->{seen}->{$key}; $self->{seen}->{$key} = 1; my $value = $self->_resolve_refs($self->_get_from_scope($key)); delete $self->{seen}->{$key}; return $value; } sub set { my ($self, $key, $value) = @_; return $self->config->{$key} = $value; } sub merge { my ( $self, %args ) = @_; my $other_conf = $self->new( %args ); for my $key ( $other_conf->config_keys ) { $self->set( $key, $other_conf->get( $key, 'no vars' ) ); } } sub resolve { my ( $self, $thing ) = @_; $self->{seen} = {}; # Can't be sure this is empty, could've croaked. return $self->_resolve_refs($thing); } sub dump { my ( $self, $file ) = @_; my $func = eval "\\&$self->{yaml_class}::" . ($file ? 'DumpFile' : 'Dump'); die "Could not find $func: $@" if $@; $func->($file ? ($file) : (), $self->config); } ############################## # Instance Methods: Private ############################## # void _resolve_refs(Scalar $value) # # Recurses on $value until a non-reference scalar is found, in which case we # defer to _resolve_scalar. In this manner things like hashes and arrays are # traversed depth-first. sub _resolve_refs { my ( $self, $value ) = @_; if ( not ref $value ) { $value = $self->_resolve_scalar($value); } elsif (ref $value eq 'HASH' ) { $value = dclone($value); my @hidden = $self->_push_scope($value); for my $key ( keys %$value ) { $value->{$key} = $self->_resolve_refs( $value->{$key} ); } $self->_pop_scope(@hidden); return $value; } elsif (ref $value eq 'ARRAY' ) { $value = dclone($value); for my $item (@$value) { $item = $self->_resolve_refs( $item ); } } elsif (ref $value eq 'SCALAR' ) { $value = $self->_resolve_scalar($$value); } else { my ($class, $type) = map ref, ($self, $value); die "${class}::_resolve_refs() can't handle $type references."; } return $value; } # List _push_scope(HashRef scope) # # Pushes a new scope onto the stack. Variables in this scope are hidden from # the seen stack. This allows us to reference variables in the current scope # even if they have the same name as a variable higher up in chain. The # hidden variables are returned. sub _push_scope { my ( $self, $scope ) = @_; unshift @{ $self->{scope_stack} }, dclone($scope); my @hidden; for my $key ( keys %$scope ) { if ( exists $self->{seen}->{$key} ) { push @hidden, $key; delete $self->{seen}->{$key}; } } return @hidden; } # void _pop_scope(@hidden) # # Removes the currently active scope from the stack and unhides any variables # passed in via @hidden, which is usually returned from _push_scope. sub _pop_scope { my ( $self, @hidden ) = @_; shift @{$self->{scope_stack}}; for my $key ( @hidden ) { $self->{seen}->{$key} = 1; # Unhide } } # void _resolve_scalar(String $value) # # This function should only be called with strings (or numbers), not # references. $value is treated as a string and is searched for $foo type # variables, which are then resolved. The new string with variables resolved # is returned. sub _resolve_scalar { my ( $self, $value ) = @_; return unless defined $value; my @parts = grep length, # Empty strings are useless, discard them split /((?_get($name) if $self->_scope_has($name); } else { # Unescape slashes. Example: \\\$foo -> \\$foo, ditto with ${foo} $part =~ s/(\\*)\\(\$(?:{(\w+)}|(\w+)))/$1$2/g; } } return $parts[0] if @parts == 1 and ref $parts[0]; # Preserve references return join "", map { defined($_) ? $_ : "" } @parts; } # HashRef _scope(void) # # Returns the current scope. There is always a currenty defined scope, even # if it's just the global scope. sub _scope { my $self = shift; return $self->{scope_stack}->[0] || $self->config; } # List _scope_stack(void) # # Returns the list of currently active scopes. The list is ordered from inner # most scope to outer most scope. The global scope is always the last scope # in the list. sub _scope_stack { my $self = shift; return ( @{ $self->{scope_stack} }, $self->config ); } # Boolean _get_from_scope(String key) # # This method returns true if the key is in any scope enclosing the current # scope or in the current scope. False otherwise. sub _scope_has { my ( $self, $name ) = @_; for my $scope ( $self->_scope_stack ) { return 1 if exists $scope->{$name}; } return 0; } # Scalar _get_from_scope(String key) # # Given a key this method returns its value as it's defined in the inner most # enclosing scope containing the key. That is to say, this method implements # the dyanmic scoping lookup for key. sub _get_from_scope { my ( $self, $key ) = @_; for my $scope ( $self->_scope_stack ) { return $scope->{$key} if exists $scope->{$key}; } return undef; } # void _load_yaml_class # # Attempts to load a YAML class that can parse YAML for us. We prefer the # yaml_class attribute over everything, then fall back to a previously loaded # YAML parser from @YAML_PREFS, and failing that try to load a parser from # @YAML_PREFS. sub _load_yaml_class { my $self = shift; # Always use what we were given. if (defined $self->{yaml_class}) { eval "require $self->{yaml_class}; 0;"; croak "$@\n" if $@; return $self->{yaml_class}; } # Use what's already been loaded. for my $module (@YAML_PREFS) { my $filename = $module . ".pm"; $filename =~ s{::}{/}; return $self->{yaml_class} = $module if exists $INC{$filename}; } # Finally, try and load something. for my $module (@YAML_PREFS) { eval "require $module; 0;"; return $self->{yaml_class} = $module unless $@; } die "Could not load: " . join(" or ", @YAML_PREFS); } # void _install_accessors(void) # # Installs convienence methods for getting and setting configuration values. # These methods are just curryed versions of get() and set(). sub _install_accessors { my $self = shift; for my $key ($self->config_keys) { next unless $key and $key =~ /^[a-zA-Z_]\w*$/; for my $method (qw(get set)) { no strict 'refs'; no warnings 'redefine'; my $method_name = ref($self) . "::${method}_$key"; *{$method_name} = sub { $_[0]->$method($key, $_[1]) }; } } } 1; __END__ =encoding UTF-8 =head1 NAME YAML::AppConfig - Manage configuration files with YAML and variable references. =head1 SYNOPSIS use YAML::AppConfig; # An extended example. YAML can also be loaded from a file. my $string = <<'YAML'; --- root_dir: /opt etc_dir: $root_dir/etc cron_dir: $etc_dir/cron.d var_dir $root_dir/var var2_dir: ${var_dir}2 usr: $root_dir/usr usr_local: $usr/local libs: system: $usr/lib local: $usr_local/lib perl: vendor: $system/perl site: $local/perl escape_example: $root_dir/\$var_dir/\\$var_dir YAML # Load the YAML::AppConfig from the given YAML. my $conf = YAML::AppConfig->new(string => $string); # Get settings in two different ways, both equivalent: $conf->get("etc_dir"); # returns /opt/etc $conf->get_etc_dir; # returns /opt/etc # Get raw settings (with no interpolation) in three equivalent ways: $conf->get("etc_dir", 1); # returns '$root_dir/etc' $conf->get_etc_dir(1); # returns '$root_dir/etc' $conf->config->{etc_dir}; # returns '$root_dir/etc' # Set etc_dir in three different ways, all equivalent. $conf->set("etc_dir", "/usr/local/etc"); $conf->set_etc_dir("/usr/local/etc"); $conf->config->{etc_dir} = "/usr/local/etc"; # Changing a setting can affect other settings: $config->get_var2_dir; # returns /opt/var2 $config->set_var_dir('/var/'); # change var_dr, which var2_dir uses. $config->get_var2_dir; # returns /var2 # Variables are dynamically scoped: $config->get_libs->{perl}->{vendor}; # returns "/opt/usr/lib/perl" # As seen above, variables are live and not static: $config->usr_dir('cows are good: $root_dir'); $config->get_usr_dir(); # returns "cows are good: /opt" $config->resolve('rm -fR $root_dir'); # returns "rm -fR /opt" # Variables can be escaped, to avoid accidental interpolation: $config->get_escape_example(); # returns "/opt/$var_dir/\$var_dir" # Merge in other configurations: my $yaml =<<'YAML'; --- root_dir: cows foo: are good YAML $config->merge(string => $yaml); $config->get_root_dir(); # returns "cows" $config->get_foo(); # returns "are good" # Get the raw YAML for your current configuration: $config->dump(); # returns YAML as string $config->dump("./conf.yaml"); # Writes YAML to ./conf.yaml =head1 DESCRIPTION L extends the work done in L and L to allow more flexible configuration files. Your configuration is stored in YAML and then parsed and presented to you via L. Settings can be referenced using C and C methods and settings can refer to one another by using variables of the form C<$foo>, much in the style of C. See L below for more details. The underlying YAML parser is either L, L or one of your choice. See L below for more information on how a YAML parser is picked. =head1 THE YAML LIBRARY At this time there are two API compatible YAML libraries for Perl. L and L. L chooses which YAML parser to use as follows: =over =item yaml_class If C is given to C then it used above all other considerations. You can use this to force use of L or L when L isn't using the one you'd like. You can also use it specify your own YAML parser, as long as it's API compatible with L and L. =item The currently loaded YAML Parser If you don't specify C then L will default to using an already loaded YAML parser, e.g. one of L or L. If both are loaded then L is preferred. =item An installed YAML Parser. If no YAML parser has already been loaded then L will attempt to load L and failing that it will attempt to load L. If both fail then L will C when you create a new object instance. =back =head1 USING VARIABLES =head2 Variable Syntax Variables refer to other settings inside the configuration file. L variables have the same form as scalar variables in Perl. That is they begin with a dollar sign and then start with a letter or an underscore and then have zero or more letters, numbers, or underscores which follow. For example, C<$foo>, C<$_bar>, and C<$cat_3> are all valid variable names. Variable names can also be contained in curly brackets so you can have a variable side-by-side with text that might otherwise be read as the name of the variable itself. For example, C<${foo}bar> is the the variable C<$foo> immediately followed by the literal text C. Without the curly brackets L would assume the variable name was C<$foobar>, which is incorrect. Variables can also be escaped by using backslashes. The text C<\$foo> will resolve to the literal string C<$foo>. Likewise C<\\$foo> will resolve to the literal string C<\$foo>, and so on. =head2 Variable Scoping YAML is essentially a serialization language and so it follows that your configuration file is just an easy to read serialization of some data structure. L assumes the top most data structure is a hash and that variables are keys in that hash, or in some hash contained within. If every hash in the configuration file is thought of as a namespace then the variables can be said to be dynamically scoped. For example, consider the following configuration file: --- foo: world bar: hello baz: - $foo - {foo: dogs, cats: $foo} - $foo $bar qux: quack: $baz In this sample configuration the array contained by C<$baz> has two elements. The first element resolves to the value C, the second element resolves to the value "dogs", and the third element resolves to C. =head2 Variable Resolving Variables can also refer to entire data structures. For example, C<$quack> will resolve to the same three element array as C<$baz>. However, YAML natively gives you this ability and then some. So consider using YAML's ability to take references to structures if L is not providing enough power for your use case. In a L object the variables are not resolved until you retrieve the variable (e.g. using C. This allows you to change settings which are used by other settings and update many settings at once. For example, if I call C then C will resolve to C. If a variable can not be resolved because it doesn't correspond to a key currently in scope then the variable will be left verbatim in the text. Consider this example: --- foo: bar: food qux: baz: $bar qix: $no_exist In this example C<$baz> resolves to the literal string C<$bar> since C<$bar> is not visible within the current scope where C<$baz> is used. Likewise, C<$qix> resolves to the literal string C<$no_exist> since there is no key in the current scope named C. =head1 METHODS =head2 new(%args) Creates a new YAML::AppConfig object and returns it. new() accepts the following key values pairs: =over 8 =item file The name of the file which contains your YAML configuration. =item string A string containing your YAML configuration. =item object A L object which will be deep copied into your object. =item no_resolve If true no attempt at variable resolution is done on calls to C. =item yaml_class The name of the class we should use to find our C and C functions for parsing YAML files and strings, respectively. The named class should provide both C and C as functions and should be loadable via C. =back =head2 get(key, [no_resolve]) Given C<$key> the value of that setting is returned, same as C. If C<$no_resolve> is true then the raw value associated with C<$key> is returned, no variable interpolation is done. It is assumed that C<$key> refers to a setting at the top level of the configuration file. =head2 set(key, value) The setting C<$key> will have its value changed to C<$value>. It is assumed that C<$key> refers to a setting at the top level of the configuration file. =head2 get_*([no_resolve]) Convenience methods to retrieve values using a method, see C. For example if C is a configuration key in top level of your YAML file then C retrieves its value. These methods are curried versions of C. These functions all take a single optional argument, C<$no_resolve>, which is the same as C C<$no_resolve>. =head2 set_*(value) Convenience methods to set values using a method, see C and C. These methods are curried versions of C. =head2 config Returns the hash reference to the raw config hash. None of the values are interpolated, this is just the raw data. =head2 config_keys Returns the keys in C sorted from first to last. =head2 merge(%args) Merge takes another YAML configuration and merges it into this one. C<%args> are the same as those passed to C, so the configuration can come from a file, string, or existing L object. =head2 resolve($scalar) C runs the internal parser on non-reference scalars and returns the result. If the scalar is a reference then it is deep copied and a copy is returned where the non-reference leaves of the data structure are parsed and replaced as described in L. =head2 dump([$file]) Serializes the current configuration using the YAML parser's Dump or, if C<$file> is given, DumpFile functions. No interpolation is done, so the configuration is saved raw. Things like comments will be lost, just as they would if you did C, because that is what what calling C on an instantiated object amounts to. =head1 AUTHORS Matthew O'Connor Ematthew@canonical.orgE Original implementations by Kirrily "Skud" Robert (as L) and Shawn Boyette (as L). Currently maintained by Grzegorz Rożniecki Exaerxess@gmail.comE. =head1 SEE ALSO L, L, L, L =head1 COPYRIGHT AND LICENSE Copyright 2006 Matthew O'Connor, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut YAML-AppConfig-0.19/META.json0000664000175000017500000000270012310536176014557 0ustar grozngrozn{ "abstract" : "Manage configuration files with YAML and variable references.", "author" : [ "Matthew O'Connor " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.92, CPAN::Meta::Converter version 2.140640", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "YAML-AppConfig", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Storable" : "0", "YAML" : "0.38", "perl" : "5.006000", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Dist/Display.html?Name=YAML-AppConfig" }, "repository" : { "type" : "git", "url" : "git://github.com/Xaerxess/YAML-AppConfig.git", "web" : "https://github.com/Xaerxess/YAML-AppConfig" } }, "version" : "0.19" } YAML-AppConfig-0.19/META.yml0000664000175000017500000000140712310536176014412 0ustar grozngrozn--- abstract: 'Manage configuration files with YAML and variable references.' author: - "Matthew O'Connor " build_requires: ExtUtils::MakeMaker: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.92, CPAN::Meta::Converter version 2.140640' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: YAML-AppConfig no_index: directory: - t - inc requires: Carp: '0' Storable: '0' YAML: '0.38' perl: '5.006000' strict: '0' warnings: '0' resources: bugtracker: https://rt.cpan.org/Dist/Display.html?Name=YAML-AppConfig repository: git://github.com/Xaerxess/YAML-AppConfig.git version: '0.19' YAML-AppConfig-0.19/README.md0000644000175000017500000000201312310535261014402 0ustar grozngroznYAML::AppConfig =============== YAML::AppConfig - Manage configuration files with YAML and variable references INSTALLATION ------------ To install the module from CPAN, use cpan YAML::AppConfig If you have the App::cpanminus installer, you may prefer cpanm YAML::AppConfig To install this module from tarball archive file containing this distribution, type perl Makefile.PL make make test make install DOCUMENTATION ------------- You can read the documentation for the module online at the following websites: * http://search.cpan.org/perldoc?YAML::AppConfig * http://metacpan.org/release/YAML::AppConfig After installing the module, you can read the documentation on your computer using perldoc YAML::AppConfig COPYRIGHT AND LICENCE --------------------- Copyright 2006 Matthew O'Connor. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. YAML-AppConfig-0.19/Makefile.PL0000644000175000017500000000354312310535725015113 0ustar grozngroznuse strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( NAME => 'YAML::AppConfig', AUTHOR => 'Matthew O\'Connor ', ABSTRACT_FROM => 'lib/YAML/AppConfig.pm', VERSION_FROM => 'lib/YAML/AppConfig.pm', MIN_PERL_VERSION => '5.6.0', PREREQ_PM => { get_yamls(), 'strict' => 0, 'warnings' => 0, 'Storable' => 0, 'Carp' => 0, }, TEST_REQUIRES => { 'Test::More' => 0, }, LICENSE => 'perl_5', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'git://github.com/Xaerxess/YAML-AppConfig.git', web => 'https://github.com/Xaerxess/YAML-AppConfig', }, bugtracker => { web => 'https://rt.cpan.org/Dist/Display.html?Name=YAML-AppConfig', }, }, }, test => { TESTS => "t/*.t" }, ); sub get_yamls { my @yamls; for my $info (['YAML::Syck' => 0], [YAML => 0.38]) { eval "require $info->[0]; 0;"; push @yamls, @$info unless $@; } die "YAML >= 0.38 or YAML::Syck >= 0 required.\n" unless @yamls; return @yamls; } unless (eval { ExtUtils::MakeMaker->VERSION(6.64) }) { my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES}; if (eval { ExtUtils::MakeMaker->VERSION(6.5503) }) { $WriteMakefileArgs{BUILD_REQUIRES} = $test_requires; } } unless (eval { ExtUtils::MakeMaker->VERSION(6.48) }) { delete $WriteMakefileArgs{MIN_PERL_VERSION}; } unless (eval { ExtUtils::MakeMaker->VERSION(6.46) }) { delete $WriteMakefileArgs{META_MERGE}; } unless (eval { ExtUtils::MakeMaker->VERSION(6.31) }) { delete $WriteMakefileArgs{LICENSE}; } WriteMakefile(%WriteMakefileArgs);