r5143 - in /packages/libconfig-any-perl/trunk: Build.PL Changes
MANIFEST
META.yml debian/changelog lib/Config/Any.pm lib/Config/Any/INI.pm
t/10-branches.t t/20-parse.t t/51-ini.t t/61-features.t t/conf/conf.foo
eloy at users.alioth.debian.org
eloy at users.alioth.debian.org
Wed Apr 18 10:36:21 UTC 2007
Author: eloy
Date: Wed Apr 18 10:36:20 2007
New Revision: 5143
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=5143
Log:
new upstream version
Added:
packages/libconfig-any-perl/trunk/t/61-features.t
- copied unchanged from r5142, packages/libconfig-any-perl/branches/upstream/current/t/61-features.t
packages/libconfig-any-perl/trunk/t/conf/conf.foo
- copied unchanged from r5142, packages/libconfig-any-perl/branches/upstream/current/t/conf/conf.foo
Modified:
packages/libconfig-any-perl/trunk/Build.PL
packages/libconfig-any-perl/trunk/Changes
packages/libconfig-any-perl/trunk/MANIFEST
packages/libconfig-any-perl/trunk/META.yml
packages/libconfig-any-perl/trunk/debian/changelog
packages/libconfig-any-perl/trunk/lib/Config/Any.pm
packages/libconfig-any-perl/trunk/lib/Config/Any/INI.pm
packages/libconfig-any-perl/trunk/t/10-branches.t
packages/libconfig-any-perl/trunk/t/20-parse.t
packages/libconfig-any-perl/trunk/t/51-ini.t
Modified: packages/libconfig-any-perl/trunk/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/Build.PL?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/Build.PL (original)
+++ packages/libconfig-any-perl/trunk/Build.PL Wed Apr 18 10:36:20 2007
@@ -13,7 +13,7 @@
'Module::Pluggable' => '3.01'
},
add_to_cleanup => [ 'Config-Any-*' ],
- create_makefile_pl => 'traditional',
+ create_makefile_pl => 'traditional',
);
$builder->create_build_script();
Modified: packages/libconfig-any-perl/trunk/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/Changes?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/Changes (original)
+++ packages/libconfig-any-perl/trunk/Changes Wed Apr 18 10:36:20 2007
@@ -5,3 +5,20 @@
0.04 Mon Aug 7 15:15:15 2006
Initial CPAN-worthy release with proper test suite
+0.05 Wed Feb 21 22:00:00 2007
+ added support for:
+ 'force_plugins => [ qw(Config::Any::Foo Config::Any::Blah) ]' parameter
+ to load_(files|stems)
+ $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY - boolean, defaulting
+ to on, controlling whether to map spaces in INI section headings
+ to nested hashrefs
+ both as requested by Evan Kaufman
+
+0.06 Thu Feb 22 21:05:00 2007
+ removed reference to Test::Exception, bumped version number
+
+0.06_01 Sun Feb 25 19:23:00 2007
+ fixed bug [rt.cpan.org #25143] make tests fails
+ - t/61_features.t had 1 more test added than was set to skip if the INI parser
+ was not installed. Fixed by s/9/10/ on the skip() line.
+
Modified: packages/libconfig-any-perl/trunk/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/MANIFEST?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/MANIFEST (original)
+++ packages/libconfig-any-perl/trunk/MANIFEST Wed Apr 18 10:36:20 2007
@@ -19,7 +19,9 @@
t/53-perl.t
t/54-xml.t
t/55-yaml.t
+t/61-features.t
t/conf/conf.conf
+t/conf/conf.foo
t/conf/conf.ini
t/conf/conf.json
t/conf/conf.pl
Modified: packages/libconfig-any-perl/trunk/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/META.yml?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/META.yml (original)
+++ packages/libconfig-any-perl/trunk/META.yml Wed Apr 18 10:36:20 2007
@@ -1,6 +1,6 @@
---
name: Config-Any
-version: 0.04
+version: 0.07
author:
- 'Joel Bernstein <rataxis at cpan.org>'
abstract: 'Load configuration from different file formats, transparently'
@@ -14,7 +14,7 @@
provides:
Config::Any:
file: lib/Config/Any.pm
- version: 0.04
+ version: 0.07
Config::Any::General:
file: lib/Config/Any/General.pm
Config::Any::INI:
@@ -27,7 +27,7 @@
file: lib/Config/Any/XML.pm
Config::Any::YAML:
file: lib/Config/Any/YAML.pm
-generated_by: Module::Build version 0.2805
+generated_by: Module::Build version 0.2806
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
Modified: packages/libconfig-any-perl/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/debian/changelog?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/debian/changelog (original)
+++ packages/libconfig-any-perl/trunk/debian/changelog Wed Apr 18 10:36:20 2007
@@ -1,3 +1,10 @@
+libconfig-any-perl (0.07-1) unstable; urgency=low
+
+ * New upstream release
+ * debian/watch updated
+
+ -- Krzysztof Krzyzaniak (eloy) <eloy at debian.org> Wed, 18 Apr 2007 12:26:17 +0200
+
libconfig-any-perl (0.04-1) unstable; urgency=low
* Initial Release (closes: #385130).
Modified: packages/libconfig-any-perl/trunk/lib/Config/Any.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/lib/Config/Any.pm?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/lib/Config/Any.pm (original)
+++ packages/libconfig-any-perl/trunk/lib/Config/Any.pm Wed Apr 18 10:36:20 2007
@@ -6,7 +6,7 @@
use Module::Pluggable::Object ();
use English qw(-no_match_vars);
-our $VERSION = '0.04';
+our $VERSION = '0.07';
=head1 NAME
@@ -14,7 +14,7 @@
=head1 VERSION
-This document describes Config::Any version 0.0.4
+This document describes Config::Any version 0.0.7
=head1 SYNOPSIS
@@ -69,6 +69,11 @@
containing YAML data will not be offered to the YAML plugin, whereas C<myapp.yml>
or C<myapp.yaml> would be.
+C<load_files()> also supports a 'force_plugins' parameter, whose value should be an
+arrayref of plugin names like C<Config::Any::INI>. Its intended use is to allow the use
+of a non-standard file extension while forcing it to be offered to a particular parser.
+It is not compatible with 'use_ext'.
+
=cut
sub load_files {
@@ -79,10 +84,10 @@
return;
}
- my $files = [ grep { -f $_ } @{$args->{files}} ];
- my $filter_cb = delete $args->{filter};
- my $use_ext = delete $args->{use_ext};
- return $class->_load($files, $filter_cb, $use_ext);
+ my %load_args = map { $_ => defined $args->{$_} ? $args->{$_} : undef }
+ qw(filter use_ext force_plugins);
+ $load_args{files} = [ grep { -f $_ } @{$args->{files}} ];
+ return $class->_load(\%load_args);
}
=head2 load_stems( )
@@ -108,9 +113,18 @@
return;
}
- my $filter_cb = delete $args->{filter};
- my $use_ext = delete $args->{use_ext};
- my $stems = $args->{stems};
+ my %load_args = map { $_ => defined $args->{$_} ? $args->{$_} : undef }
+ qw(filter use_ext force_plugins);
+
+ my $filenames = $class->_stems_to_files($args->{stems});
+ $load_args{files} = [ grep { -f $_ } @{$filenames} ];
+ return $class->_load(\%load_args);
+}
+
+sub _stems_to_files {
+ my ($class, $stems) = @_;
+ return unless defined $stems;
+
my @files;
STEM:
for my $s (@$stems) {
@@ -122,37 +136,46 @@
last EXT;
}
}
- return $class->_load(\@files, $filter_cb, $use_ext);
-}
+ \@files;
+}
+
+sub _maphash (@) { map { $_ => 1 } @_ } # sugar
# this is where we do the real work
# it's a private class-method because users should use the interface described
# in the POD.
sub _load {
- my ($class, $files_ref, $filter_cb, $use_ext) = @_;
+ my ($class, $args) = @_;
+ my ($files_ref, $filter_cb, $use_ext, $force_plugins_ref) =
+ @{$args}{qw(files filter use_ext force_plugins)};
croak "_load requires a arrayref of file paths" unless defined $files_ref;
+
+ my %files = _maphash @$files_ref;
+ my %force_plugins = _maphash @$force_plugins_ref;
+ my $enforcing = keys %force_plugins ? 1 : 0;
my $final_configs = [];
my $originally_loaded = {};
- my %files = map { $_ => 1 } @$files_ref;
-
+
+ # perform a separate file loop for each loader
for my $loader ( $class->plugins ) {
+ next if $enforcing && not defined $force_plugins{$loader};
last unless keys %files;
-# warn "loader: $loader\n";
- my %ext = map { $_ => 1 } $loader->extensions;
+ my %ext = _maphash $loader->extensions;
+
FILE:
for my $filename (keys %files) {
- if (defined $use_ext) {
-# warn "using file extension to decide which loader to use for file $filename\n";
+ # use file extension to decide whether this loader should try this file
+ # use_ext => 1 hits this block
+ if (defined $use_ext && !$enforcing) {
my $matched_ext = 0;
EXT:
for my $e (keys %ext) {
-# warn "trying ext $e\n";
next EXT unless $filename =~ m{ \. $e \z }xms;
-# warn "filename $filename matched extension $e\n";
next FILE unless exists $ext{$e};
$matched_ext = 1;
}
+
next FILE unless $matched_ext;
}
@@ -160,11 +183,14 @@
eval {
$config = $loader->load( $filename );
};
- next if $EVAL_ERROR;
+
+ next if $EVAL_ERROR; # if it croaked or warned, we can't use it
next if !$config;
delete $files{$filename};
-# warn "loader $loader loaded file $filename\n";
+
+ # post-process config with a filter callback, if we got one
$filter_cb->( $config ) if defined $filter_cb;
+
push @$final_configs, { $filename => $config };
}
}
@@ -273,9 +299,12 @@
With ideas and support from Matt S Trout C<< <mst at shadowcatsystems.co.uk> >>.
+Further enhancements suggested by Evan Kaufman C<< <evank at cpan.org> >>.
+
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2006, Portugal Telecom C<< http://www.sapo.pt/ >>. All rights reserved.
+Portions copyright 2007, Joel Bernstein C<< <rataxis at cpan.org> >>.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
@@ -310,5 +339,4 @@
=cut
-1; # Magic true value required at end of module
-
+"Drink more beer";
Modified: packages/libconfig-any-perl/trunk/lib/Config/Any/INI.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/lib/Config/Any/INI.pm?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/lib/Config/Any/INI.pm (original)
+++ packages/libconfig-any-perl/trunk/lib/Config/Any/INI.pm Wed Apr 18 10:36:20 2007
@@ -2,6 +2,8 @@
use strict;
use warnings;
+
+our $MAP_SECTION_SPACE_TO_NESTED_KEY = 1;
=head1 NAME
@@ -49,7 +51,7 @@
$out->{$_} = $main->{$_} for keys %$main;
for my $k (keys %$config) {
- my @keys = split /\s+/, $k;
+ my @keys = split /\s+/, $k if $MAP_SECTION_SPACE_TO_NESTED_KEY;
my $ref = $config->{$k};
if (@keys > 1) {
@@ -61,6 +63,25 @@
}
return $out;
}
+
+=head1 PACKAGE VARIABLES
+
+=over 4
+
+=item $MAP_SECTION_SPACE_TO_NESTED_KEY (boolean)
+
+This variable controls whether spaces in INI section headings will be expanded into nested hash keys.
+e.g. it controls whether [Full Power] maps to $config->{'Full Power'} or $config->{'Full'}->{'Power'}
+
+By default it is set to 1 (i.e. true).
+
+Set it to 0 to preserve literal spaces in section headings:
+
+ use Config::Any;
+ use Config::Any::INI;
+ $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
+
+=back
=head1 AUTHOR
@@ -74,7 +95,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright 2006 by Brian Cassidy
+Copyright 2006 by Brian Cassidy, portions copyright 2006, 2007 by Joel Bernstein
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Modified: packages/libconfig-any-perl/trunk/t/10-branches.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/t/10-branches.t?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/t/10-branches.t (original)
+++ packages/libconfig-any-perl/trunk/t/10-branches.t Wed Apr 18 10:36:20 2007
@@ -1,5 +1,4 @@
use Test::More tests => 9;
-use Test::Exception;
use Config::Any;
ok ( ! Config::Any->load_files(), "load_files expects args" );
Modified: packages/libconfig-any-perl/trunk/t/20-parse.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/t/20-parse.t?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/t/20-parse.t (original)
+++ packages/libconfig-any-perl/trunk/t/20-parse.t Wed Apr 18 10:36:20 2007
@@ -1,5 +1,8 @@
package MockApp;
+use strict;
+use warnings;
+$|++;
use Test::More tests => 54;
use Scalar::Util qw(blessed reftype);
use Config::Any;
@@ -11,7 +14,7 @@
use Config::Any::YAML;
-my %ext_map = (
+our %ext_map = (
conf => 'Config::Any::General',
ini => 'Config::Any::INI',
json => 'Config::Any::JSON',
@@ -20,20 +23,24 @@
yml => 'Config::Any::YAML'
);
-my @files = map { "t/conf/$_" }
- qw(conf.conf conf.ini conf.json conf.pl conf.xml conf.yml);
+sub load_parser_for {
+ my $f = shift;
+ return unless $f;
-for my $f (@files) {
my ($ext) = $f =~ m{ \. ( [^\.]+ ) \z }xms;
my $mod = $ext_map{$ext};
my $mod_load_result;
eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' };
+ return $@ ? (1,$mod) : (0,$mod);
+}
+
+for my $f (map { "t/conf/conf.$_" } keys %ext_map) {
+ my ($skip,$mod) = load_parser_for($f);
SKIP: {
- my $skip = !!$@;
skip "File loading backend for $mod not found", 9 if $skip;
ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}),
- "load_files with use_ext works");
+ "load_files with use_ext works [$f]");
ok(my $c = $c_arr->[0], "load_files returns an arrayref");
ok(ref $c, "load_files arrayref contains a ref");
Modified: packages/libconfig-any-perl/trunk/t/51-ini.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libconfig-any-perl/trunk/t/51-ini.t?rev=5143&op=diff
==============================================================================
--- packages/libconfig-any-perl/trunk/t/51-ini.t (original)
+++ packages/libconfig-any-perl/trunk/t/51-ini.t Wed Apr 18 10:36:20 2007
@@ -1,17 +1,26 @@
-use Test::More tests => 6;
-
-use Config::Any::INI;
-
-my $config = eval { Config::Any::INI->load( 't/conf/conf.ini' ) };
-my $simpleconfig = eval { Config::Any::INI->load( 't/conf/conf2.ini' ) };
-
-SKIP: {
- skip "Couldn't Load INI plugin", 6 if $@;
- ok( $config );
- is( $config->{ name }, 'TestApp' );
- is( $config->{Component}->{Controller::Foo}->{foo}, 'bar');
-
- ok( $simpleconfig );
- is( $simpleconfig->{ name }, 'TestApp' );
- is( $simpleconfig->{Controller::Foo}->{foo}, 'bar' );
-}
+use Test::More tests => 9;
+
+use Config::Any::INI;
+
+my $config = eval { Config::Any::INI->load( 't/conf/conf.ini' ) };
+my $simpleconfig = eval { Config::Any::INI->load( 't/conf/conf2.ini' ) };
+
+SKIP: {
+ skip "Couldn't Load INI plugin", 6 if $@;
+ ok( $config, "loaded INI config #1" );
+ is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
+ is( $config->{Component}->{Controller::Foo}->{foo}, 'bar', "nested hashref hack lookup succeeded");
+
+ ok( $simpleconfig, "loaded INI config #1" );
+ is( $simpleconfig->{ name }, 'TestApp', "toplevel key lookup succeeded" );
+ is( $simpleconfig->{Controller::Foo}->{foo}, 'bar', "nested hashref hack lookup succeeded" );
+}
+
+$Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
+my $unspaced_config = eval { Config::Any::INI->load( 't/conf/conf.ini' ); };
+SKIP: {
+ skip "Couldn't load INI plugin", 3 if $@;
+ ok( $unspaced_config, "loaded INI config #1 in no-map-space mode" );
+ is( $unspaced_config->{name}, 'TestApp', "toplevel key lookup succeeded" );
+ is( $unspaced_config->{'Component Controller::Foo'}->{foo}, 'bar', "unnested key lookup succeeded");
+}
More information about the Pkg-perl-cvs-commits
mailing list