From: Brian Cassidy Date: Sun, 20 Aug 2006 02:18:06 +0000 (+0000) Subject: add missing files X-Git-Tag: v0.13~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d4ffe6e012e32e98b9598c1defe4e8c8b5fc25d6;hp=a6f708d5373870c22f8280a04d6c47cad9a53395;p=catagits%2FCatalyst-Plugin-ConfigLoader.git add missing files --- 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 new file mode 100644 index 0000000..9c24cab --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/INI.pm @@ -0,0 +1,82 @@ +package Catalyst::Plugin::ConfigLoader::INI; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::INI - Load INI config files + +=head1 DESCRIPTION + +Loads INI files. Example: + + name=TestApp + + [Controller::Foo] + foo=bar + + [Model::Baz] + qux=xyzzy + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C). + +=cut + +sub extensions { + return qw( ini ); +} + +=head2 load( $file ) + +Attempts to load C<$file> as an INI file. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + require Config::Tiny; + my $config = Config::Tiny->read( $file ); + my $main = delete $config->{ _ }; + + $config->{ $_ } = $main->{ $_ } for keys %$main; + + 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/JSON.pm b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm new file mode 100644 index 0000000..1c100ce --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm @@ -0,0 +1,92 @@ +package Catalyst::Plugin::ConfigLoader::JSON; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::JSON - Load JSON config files + +=head1 DESCRIPTION + +Loads JSON files. Example: + + { + "name": "TestApp", + "Controller::Foo": { + "foo": "bar" + }, + "Model::Baz": { + "qux": "xyzzy" + } + } + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C, C). + +=cut + +sub extensions { + return qw( json jsn ); +} + +=head2 load( $file ) + +Attempts to load C<$file> as a JSON file. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + open( my $fh, $file ) or die $!; + my $content = do { local $/; <$fh> }; + close $fh; + + eval { require JSON::Syck; }; + if( $@ ) { + require JSON; + JSON->import; + return jsonToObj( $content ); + } + else { + return JSON::Syck::Load( $content ); + } +} + +=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 + +=item * L + +=back + +=cut + +1; \ No newline at end of file diff --git a/lib/Catalyst/Plugin/ConfigLoader/Perl.pm b/lib/Catalyst/Plugin/ConfigLoader/Perl.pm new file mode 100644 index 0000000..e94edba --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/Perl.pm @@ -0,0 +1,76 @@ +package Catalyst::Plugin::ConfigLoader::Perl; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::Perl - Load Perl config files + +=head1 DESCRIPTION + +Loads Perl files. Example: + + { + name => 'TestApp', + 'Controller::Foo' => { + foo => 'bar' + }, + 'Model::Baz' => { + qux => 'xyzzy' + } + } + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C, C). + +=cut + +sub extensions { + return qw( pl perl ); +} + +=head2 load( $file ) + +Attempts to load C<$file> as a Perl file. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + return eval { require $file }; +} + +=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 + +=back + +=cut + +1; \ No newline at end of file diff --git a/lib/Catalyst/Plugin/ConfigLoader/XML.pm b/lib/Catalyst/Plugin/ConfigLoader/XML.pm new file mode 100644 index 0000000..f44346c --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/XML.pm @@ -0,0 +1,82 @@ +package Catalyst::Plugin::ConfigLoader::XML; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::XML - Load XML config files + +=head1 DESCRIPTION + +Loads XML files. Example: + + + TestApp + + bar + + + xyzzy + + + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C). + +=cut + +sub extensions { + return qw( xml ); +} + +=head2 load( $file ) + +Attempts to load C<$file> as an XML file. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + require XML::Simple; + XML::Simple->import; + my $config = XMLin( $file, ForceArray => [ qw( component model view controller ) ] ); + + 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/YAML.pm b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm new file mode 100644 index 0000000..f1e6a86 --- /dev/null +++ b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm @@ -0,0 +1,88 @@ +package Catalyst::Plugin::ConfigLoader::YAML; + +use strict; +use warnings; + +=head1 NAME + +Catalyst::Plugin::ConfigLoader::YAML - Load YAML config files + +=head1 DESCRIPTION + +Loads YAML files. Example: + + --- + name: TestApp + Controller::Foo: + foo: bar + Model::Baz: + qux: xyzzy + + +=head1 METHODS + +=head2 extensions( ) + +return an array of valid extensions (C, C). + +=cut + +sub extensions { + return qw( yml yaml ); +} + +=head2 load( $file ) + +Attempts to load C<$file> as a YAML file. + +=cut + +sub load { + my $class = shift; + my $file = shift; + + eval { require YAML::Syck; }; + if( $@ ) { + require YAML; + return YAML::LoadFile( $file ); + } + else { + open( my $fh, $file ) or die $!; + my $content = do { local $/; <$fh> }; + close $fh; + return YAML::Syck::Load( $content ); + } +} + +=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 + +=item * L + +=back + +=cut + +1; \ No newline at end of file