[Catalyst-commits] r7126 - in trunk/Config-Any: . lib/Config lib/Config/Any t

bricas at dev.catalyst.perl.org bricas at dev.catalyst.perl.org
Tue Nov 13 15:40:45 GMT 2007


Author: bricas
Date: 2007-11-13 15:40:44 +0000 (Tue, 13 Nov 2007)
New Revision: 7126

Modified:
   trunk/Config-Any/Changes
   trunk/Config-Any/lib/Config/Any.pm
   trunk/Config-Any/lib/Config/Any/General.pm
   trunk/Config-Any/lib/Config/Any/INI.pm
   trunk/Config-Any/lib/Config/Any/JSON.pm
   trunk/Config-Any/lib/Config/Any/Perl.pm
   trunk/Config-Any/lib/Config/Any/XML.pm
   trunk/Config-Any/lib/Config/Any/YAML.pm
   trunk/Config-Any/t/10-branches.t
   trunk/Config-Any/t/62-multi.t
Log:
added is_supported() to see what plugins we can use

Modified: trunk/Config-Any/Changes
===================================================================
--- trunk/Config-Any/Changes	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/Changes	2007-11-13 15:40:44 UTC (rev 7126)
@@ -6,7 +6,9 @@
     - 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

Modified: trunk/Config-Any/lib/Config/Any/General.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/General.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/General.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -68,6 +68,17 @@
     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 at cpan.orgE<gt>

Modified: trunk/Config-Any/lib/Config/Any/INI.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/INI.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/INI.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -65,6 +65,17 @@
     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

Modified: trunk/Config-Any/lib/Config/Any/JSON.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/JSON.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/JSON.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -57,6 +57,19 @@
     }
 }
 
+=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 at cpan.orgE<gt>

Modified: trunk/Config-Any/lib/Config/Any/Perl.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/Perl.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/Perl.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -54,6 +54,16 @@
     return $content;
 }
 
+=head2 is_supported( )
+
+Returns true.
+
+=cut
+
+sub is_supported {
+    return 1;
+}
+
 =head1 AUTHOR
 
 Brian Cassidy E<lt>bricas at cpan.orgE<gt>

Modified: trunk/Config-Any/lib/Config/Any/XML.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/XML.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/XML.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -73,6 +73,17 @@
     $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 at cpan.orgE<gt>

Modified: trunk/Config-Any/lib/Config/Any/YAML.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/YAML.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any/YAML.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -54,6 +54,19 @@
     }
 }
 
+=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 at cpan.orgE<gt>

Modified: trunk/Config-Any/lib/Config/Any.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any.pm	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/lib/Config/Any.pm	2007-11-13 15:40:44 UTC (rev 7126)
@@ -133,19 +133,21 @@
     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;
         }
@@ -164,19 +166,21 @@
     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;
@@ -187,7 +191,8 @@
                 $args->{ filter }->( $_ ) for @configs;
             }
 
-            push @results, { $filename => @configs == 1 ? $configs[ 0 ] : \@configs };
+            push @results,
+                { $filename => @configs == 1 ? $configs[ 0 ] : \@configs };
             last;
         }
     }

Modified: trunk/Config-Any/t/10-branches.t
===================================================================
--- trunk/Config-Any/t/10-branches.t	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/t/10-branches.t	2007-11-13 15:40:44 UTC (rev 7126)
@@ -6,7 +6,7 @@
     my @warnings;
     local $SIG{ __WARN__ } = sub { push @warnings, @_ };
 
-    Config::Any->load_files( );
+    Config::Any->load_files();
     like(
         shift @warnings,
         qr/^No files specified!/,
@@ -20,7 +20,7 @@
         "load_files expects files"
     );
 
-    Config::Any->load_stems( );
+    Config::Any->load_stems();
     like(
         shift @warnings,
         qr/^No stems specified!/,

Modified: trunk/Config-Any/t/62-multi.t
===================================================================
--- trunk/Config-Any/t/62-multi.t	2007-11-13 15:21:57 UTC (rev 7125)
+++ trunk/Config-Any/t/62-multi.t	2007-11-13 15:40:44 UTC (rev 7126)
@@ -23,6 +23,11 @@
     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'
+    );
 }




More information about the Catalyst-commits mailing list