- when use_ext is on, if a parser throws an error, we throw an error
- fix case where use_ext is defined and false, but was behaving like
use_ext => 1
- - allow loaders to return multiple documents as an array.
+ - allow loaders to return multiple documents as an array
+ - each plugin now has an is_supported() which helps us figure out if
+ the right modules are available
0.08 Thu Aug 23 2007
- pass config options to each parser
my ( $class, $args ) = @_;
croak "_load requires a arrayref of file paths" unless $args->{ files };
- if( !defined $args->{ use_ext } ) {
- warn "use_ext argument was not explicitly set, as of 0.09, this is true by default";
+ if ( !defined $args->{ use_ext } ) {
+ warn
+ "use_ext argument was not explicitly set, as of 0.09, this is true by default";
$args->{ use_ext } = 1;
}
# figure out what plugins we're using
- my $force = defined $args->{ force_plugins };
- my @plugins = $force ? @{ $args->{ force_plugins } } : $class->plugins;
+ my $force = defined $args->{ force_plugins };
+ my @plugins = grep { $_->is_supported }
+ ( $force ? @{ $args->{ force_plugins } } : $class->plugins );
# map extensions if we have to
- my( %extension_lut, $extension_re );
+ my ( %extension_lut, $extension_re );
my $use_ext_lut = !$force && $args->{ use_ext };
- if( $use_ext_lut ) {
+ if ( $use_ext_lut ) {
for my $plugin ( @plugins ) {
$extension_lut{ $_ } = $plugin for $plugin->extensions;
}
my @results;
for my $filename ( @{ $args->{ files } } ) {
+
# don't even bother if it's not there
next unless -f $filename;
my @try_plugins = @plugins;
- if( $use_ext_lut ) {
+ if ( $use_ext_lut ) {
$filename =~ m{\.($extension_re)\z};
next unless $1;
@try_plugins = $extension_lut{ $1 };
}
for my $loader ( @try_plugins ) {
- my @configs = eval { $loader->load( $filename, $loader_args{ $loader } ); };
+ my @configs
+ = eval { $loader->load( $filename, $loader_args{ $loader } ); };
# fatal error if we used extension matching
croak "Error parsing file: $filename" if $@ and $use_ext_lut;
$args->{ filter }->( $_ ) for @configs;
}
- push @results, { $filename => @configs == 1 ? $configs[ 0 ] : \@configs };
+ push @results,
+ { $filename => @configs == 1 ? $configs[ 0 ] : \@configs };
last;
}
}
return defined $is_perl_src;
}
+=head2 is_supported( )
+
+Returns true if L<Config::General> is available.
+
+=cut
+
+sub is_supported {
+ eval { require Config::General; };
+ return $@ ? 0 : 1;
+}
+
=head1 AUTHOR
Brian Cassidy E<lt>bricas@cpan.orgE<gt>
return $out;
}
+=head2 is_supported( )
+
+Returns true if L<Config::Tiny> is available.
+
+=cut
+
+sub is_supported {
+ eval { require Config::Tiny; };
+ return $@ ? 0 : 1;
+}
+
=head1 PACKAGE VARIABLES
=over 4
}
}
+=head2 is_supported( )
+
+Returns true if either L<JSON::Syck> or L<JSON> is available.
+
+=cut
+
+sub is_supported {
+ eval { require JSON::Syck; };
+ return 1 unless $@;
+ eval { require JSON; };
+ return $@ ? 0 : 1;
+}
+
=head1 AUTHOR
Brian Cassidy E<lt>bricas@cpan.orgE<gt>
return $content;
}
+=head2 is_supported( )
+
+Returns true.
+
+=cut
+
+sub is_supported {
+ return 1;
+}
+
=head1 AUTHOR
Brian Cassidy E<lt>bricas@cpan.orgE<gt>
$out;
}
+=head2 is_supported( )
+
+Returns true if L<XML::Simple> is available.
+
+=cut
+
+sub is_supported {
+ eval { require XML::Simple; };
+ return $@ ? 0 : 1;
+}
+
=head1 AUTHORS
Brian Cassidy E<lt>bricas@cpan.orgE<gt>
}
}
+=head2 is_supported( )
+
+Returns true if either L<YAML::Syck> or L<YAML> is available.
+
+=cut
+
+sub is_supported {
+ eval { require YAML::Syck; };
+ return 1 unless $@;
+ eval { require YAML; };
+ return $@ ? 0 : 1;
+}
+
=head1 AUTHOR
Brian Cassidy E<lt>bricas@cpan.orgE<gt>
my @warnings;
local $SIG{ __WARN__ } = sub { push @warnings, @_ };
- Config::Any->load_files( );
+ Config::Any->load_files();
like(
shift @warnings,
qr/^No files specified!/,
"load_files expects files"
);
- Config::Any->load_stems( );
+ Config::Any->load_stems();
like(
shift @warnings,
qr/^No stems specified!/,
is( @results, 2, '2 documents' );
is_deeply( \@results, \@expect, 'structures ok' );
- my $return = Config::Any->load_files( { use_ext => 1, files => [ $file ] } );
- is_deeply( $return, [ { $file => \@expect } ], 'config-any structures ok' );
+ my $return
+ = Config::Any->load_files( { use_ext => 1, files => [ $file ] } );
+ is_deeply(
+ $return,
+ [ { $file => \@expect } ],
+ 'config-any structures ok'
+ );
}