=head2 load_stems( )
- Config::Any->load_stems({stems => \@stems]});
- Config::Any->load_stems({stems => \@stems, filter => \&filter});
- Config::Any->load_stems({stems => \@stems, use_ext => 1});
+ Config::Any->load_stems( { stems => \@stems } );
+ Config::Any->load_stems( { stems => \@stems, filter => \&filter } );
+ Config::Any->load_stems( { stems => \@stems, use_ext => 1 } );
C<load_stems()> attempts to load configuration from a list of files which it generates
by combining the filename stems list passed in the C<stems> parameter with the
sub load_stems {
my ( $class, $args ) = @_;
- return unless defined $args;
- unless ( exists $args->{ stems } ) {
- warn "no stems specified";
+
+ unless ( $args && exists $args->{ stems } ) {
+ warn "No stems specified!";
return;
}
- my %load_args
- = map { $_ => defined $args->{ $_ } ? $args->{ $_ } : undef }
- qw(filter use_ext force_plugins driver_args);
-
- $load_args{ files } = $class->_stems_to_files( $args->{ stems } );
- return $class->_load( \%load_args );
-}
-
-sub _stems_to_files {
- my ( $class, $stems ) = @_;
- return unless defined $stems;
-
+ my $stems = delete $args->{ stems };
my @files;
for my $s ( @$stems ) {
for my $ext ( $class->extensions ) {
push @files, "$s.$ext";
}
}
- return \@files;
-}
-sub _maphash { # syntactic sugar
- map { $_ => 1 } @_;
-}
+ $args->{ files } = \@files;
+ return $class->_load( $args );
+}
# this is where we do the real work
# it's a private class-method because users should use the interface described
= @{ $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 %files = map { $_ => 1 } @$files_ref;
+ my %force_plugins = map { $_ => 1 } @$force_plugins_ref;
my $enforcing = keys %force_plugins ? 1 : 0;
my $final_configs = [];
for my $loader ( $class->plugins ) {
next if $enforcing && not defined $force_plugins{ $loader };
last unless keys %files;
- my %ext = _maphash $loader->extensions;
+ my %ext = map { $_ => 1 } $loader->extensions;
my ( $loader_class ) = $loader =~ /::([^:]+)$/;
my $driver_args = $args->{ driver_args }{ $loader_class } || {};
search_path => [ __PACKAGE__ ],
require => 1
);
- $finder;
+ return $finder;
}
=head2 plugins( )
-use Test::More tests => 9;
-use Config::Any;
+use Test::More tests => 10;
-ok( !Config::Any->load_stems(), "load_stems expects args" );
+use_ok( 'Config::Any' );
{
my @warnings;
"load_files expects files"
);
+ Config::Any->load_stems( );
+ like(
+ shift @warnings,
+ qr/^No stems specified!/,
+ "load_stems expects args"
+ );
+
Config::Any->load_stems( {} );
like(
shift @warnings,
- qr/^no stems specified/,
+ qr/^No stems specified!/,
"load_stems expects stems"
);
}