From: Brian Cassidy Date: Mon, 1 May 2006 12:22:31 +0000 (+0000) Subject: added Config::General support X-Git-Tag: v0.07~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1502c00950aee234a54176dd6ffa92973aa55175;hp=06b5f4a9a71a1c3781c6074c9bc701e1581785ac;p=catagits%2FCatalyst-Plugin-ConfigLoader.git added Config::General support added nicer syntax for models/views/controllers --- diff --git a/Changes b/Changes index b0194a7..4cd05ba 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl extension Catalyst::Plugin::ConfigLoader. +0.07 Mon May 01 2006 + - added Config::General support + - added nicer syntax for specifying models/views/controllers where + available + 0.06 Wed Apr 26 2006 - remove "last;" so that _local configs will be processed diff --git a/lib/Catalyst/Plugin/ConfigLoader.pm b/lib/Catalyst/Plugin/ConfigLoader.pm index c50c0f5..7ec10fa 100644 --- a/lib/Catalyst/Plugin/ConfigLoader.pm +++ b/lib/Catalyst/Plugin/ConfigLoader.pm @@ -10,7 +10,7 @@ use Module::Pluggable::Fast require => 1; use Data::Visitor::Callback; -our $VERSION = '0.06'; +our $VERSION = '0.07'; =head1 NAME @@ -68,6 +68,9 @@ sub setup { for( @files ) { next unless -f $_; my $config = $loader->load( $_ ); + + _fix_syntax( $config ); + $c->config( $config ) if $config; } } @@ -104,6 +107,23 @@ sub finalize_config { $v->visit( $c->config ); } +sub _fix_syntax { + my $config = shift; + my @components = ( + map +{ + prefix => $_ eq 'Component' ? '' : $_ . '::', + values => delete $config->{ lc $_ } || delete $config->{ $_ } + }, qw( Component Model View Controller ) + ); + + foreach my $comp ( @components ) { + my $prefix = $comp->{ prefix }; + foreach my $element ( keys %{ $comp->{ values } } ) { + $config->{ "$prefix$element" } = $comp->{ values }->{ $element }; + } + } +} + =head1 AUTHOR =over 4 diff --git a/lib/Catalyst/Plugin/ConfigLoader/General.pm b/lib/Catalyst/Plugin/ConfigLoader/General.pm new file mode 100644 index 0000000..f6e8d16 --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/General.pm @@ -0,0 +1,80 @@ +package Catalyst::Plugin::ConfigLoader::General; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::General - Load Config::General files + +=head1 DESCRIPTION + +Loads Config::General files. Example: + + name = TestApp + + foo bar + + + qux xyzzy + + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C, C). + +=cut + +sub extensions { + return qw( cnf conf ); +} + +=head2 load( $file ) + +Attempts to load C<$file> via Config::General. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + require Config::General; + my $configfile = Config::General->new( $file ); + my $config = { $configfile->getall }; + + return $config; +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Brian Cassidy + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=head1 SEE ALSO + +=over 4 + +=item * L + +=item * L + +=item * L + +=back + +=cut + +1; \ No newline at end of file diff --git a/lib/Catalyst/Plugin/ConfigLoader/INI.pm b/lib/Catalyst/Plugin/ConfigLoader/INI.pm index a5c28f6..f254e86 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/INI.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/INI.pm @@ -70,6 +70,8 @@ it under the same terms as Perl itself. =item * L +=item * L + =back =cut diff --git a/lib/Catalyst/Plugin/ConfigLoader/JSON.pm b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm index 248543b..3a8b539 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/JSON.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm @@ -78,6 +78,10 @@ it under the same terms as Perl itself. =item * L +=item * L + +=item * L + =back =cut diff --git a/lib/Catalyst/Plugin/ConfigLoader/Perl.pm b/lib/Catalyst/Plugin/ConfigLoader/Perl.pm index 205f11c..6cfec00 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/Perl.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/Perl.pm @@ -12,7 +12,7 @@ Catalyst::Plugin::ConfigLoader::Perl - Load Perl config files Loads Perl files. Example: { - name => 'TestApp', + name => 'TestApp', Controller::Foo => { foo => 'bar' } diff --git a/lib/Catalyst/Plugin/ConfigLoader/XML.pm b/lib/Catalyst/Plugin/ConfigLoader/XML.pm index 9fb2ab4..f44346c 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/XML.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/XML.pm @@ -16,6 +16,9 @@ Loads XML files. Example: bar + + xyzzy + =head1 METHODS @@ -42,12 +45,7 @@ sub load { require XML::Simple; XML::Simple->import; - my $config = XMLin( $file, ForceArray => [ 'component' ] ); - - my $components = delete $config->{ component }; - foreach my $element ( keys %$components ) { - $config->{ $element } = $components->{ $element }; - } + my $config = XMLin( $file, ForceArray => [ qw( component model view controller ) ] ); return $config; } diff --git a/lib/Catalyst/Plugin/ConfigLoader/YAML.pm b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm index 88683dc..3e521ff 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/YAML.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm @@ -74,6 +74,10 @@ it under the same terms as Perl itself. =item * L +=item * L + +=item * L + =back =cut