From: Brian Cassidy Date: Thu, 8 Nov 2007 14:21:58 +0000 (+0000) Subject: some code and pod cleanups. X-Git-Tag: v0.09_01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4efab5582d1ec3acd99a2ffb898bed58d5f2420b;p=p5sagit%2FConfig-Any.git some code and pod cleanups. --- diff --git a/Changes b/Changes index 2592d56..ce9363b 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Config-Any +0.09 Thu Nov 08 2007 + code and pod cleanups + 0.08 Thu Aug 23 2007 pass config options to each parser fix for loading the same perl config twice (RT #28812) diff --git a/lib/Config/Any.pm b/lib/Config/Any.pm index 031a0e2..4f9b401 100644 --- a/lib/Config/Any.pm +++ b/lib/Config/Any.pm @@ -7,7 +7,7 @@ use Carp; use Module::Pluggable::Object (); use English qw(-no_match_vars); -our $VERSION = '0.08'; +our $VERSION = '0.09'; =head1 NAME @@ -51,9 +51,9 @@ configuration formats. =head2 load_files( ) - Config::Any->load_files({files => \@files}); - Config::Any->load_files({files => \@files, filter => \&filter}); - Config::Any->load_files({files => \@files, use_ext => 1}); + Config::Any->load_files( { files => \@files } ); + Config::Any->load_files( { files => \@files, filter => \&filter } ); + Config::Any->load_files( { files => \@files, use_ext => 1 } ); C attempts to load configuration from the list of files passed in the C parameter, if the file exists. @@ -86,17 +86,13 @@ parser object. Example: sub load_files { my ( $class, $args ) = @_; - return unless defined $args; - unless ( exists $args->{ files } ) { - warn "no files specified"; + + unless ( $args && exists $args->{ files } ) { + warn "No files specified!"; return; } - my %load_args - = map { $_ => defined $args->{ $_ } ? $args->{ $_ } : undef } - qw(filter use_ext force_plugins driver_args); - $load_args{ files } = [ grep { -f $_ } @{ $args->{ files } } ]; - return $class->_load( \%load_args ); + return $class->_load( $args ); } =head2 load_stems( ) @@ -126,8 +122,7 @@ sub load_stems { = map { $_ => defined $args->{ $_ } ? $args->{ $_ } : undef } qw(filter use_ext force_plugins driver_args); - my $filenames = $class->_stems_to_files( $args->{ stems } ); - $load_args{ files } = [ grep { -f $_ } @{ $filenames } ]; + $load_args{ files } = $class->_stems_to_files( $args->{ stems } ); return $class->_load( \%load_args ); } @@ -136,22 +131,17 @@ sub _stems_to_files { return unless defined $stems; my @files; -STEM: for my $s ( @$stems ) { - EXT: for my $ext ( $class->extensions ) { - my $file = "$s.$ext"; - next EXT unless -f $file; - push @files, $file; - last EXT; + push @files, "$s.$ext"; } } - \@files; + return \@files; } -sub _maphash (@) { +sub _maphash { # syntactic sugar map { $_ => 1 } @_; -} # sugar +} # this is where we do the real work # it's a private class-method because users should use the interface described @@ -180,6 +170,7 @@ sub _load { FILE: for my $filename ( keys %files ) { + next unless -f $filename; # use file extension to decide whether this loader should try this file # use_ext => 1 hits this block @@ -252,7 +243,7 @@ parameter to those methods. sub extensions { my $class = shift; my @ext = map { $_->extensions } $class->plugins; - return wantarray ? @ext : [ @ext ]; + return wantarray ? @ext : \@ext; } =head1 DIAGNOSTICS diff --git a/t/10-branches.t b/t/10-branches.t index adda42d..90dc25b 100644 --- a/t/10-branches.t +++ b/t/10-branches.t @@ -1,18 +1,26 @@ use Test::More tests => 9; use Config::Any; -ok( !Config::Any->load_files(), "load_files expects args" ); ok( !Config::Any->load_stems(), "load_stems expects args" ); { my @warnings; local $SIG{ __WARN__ } = sub { push @warnings, @_ }; + + Config::Any->load_files( ); + like( + shift @warnings, + qr/^No files specified!/, + "load_files expects args" + ); + Config::Any->load_files( {} ); like( shift @warnings, - qr/^no files specified/, + qr/^No files specified!/, "load_files expects files" ); + Config::Any->load_stems( {} ); like( shift @warnings,