From: Sebastian Riedel Date: Sat, 7 Jan 2006 02:18:01 +0000 (+0000) Subject: Added YAML config support X-Git-Tag: 5.7099_04~759 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=99f187d63f41e5d1fe740ab280192c3d42c28690 Added YAML config support --- diff --git a/Changes b/Changes index deb124f..79b8b6d 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ This file documents the revision history for Perl extension Catalyst. 5.62 + - Added YAML config support - Added COMPONENT() and ACCEPT_CONTEXT() support - Action list in debug mode is now displayed as a tree in the correct execution order. diff --git a/Makefile.PL b/Makefile.PL index 30a9218..bf7c59e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -31,6 +31,7 @@ requires 'Tree::Simple::Visitor::FindByPath'; requires 'URI' => 1.35; requires 'File::Copy::Recursive'; requires 'Module::Install::Admin' => '0.45'; +requires 'YAML'; feature 'Apache/mod_perl Support', -default => 0, diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 42cbe8f..c5c315e 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -20,6 +20,7 @@ use Scalar::Util qw/weaken/; use Tree::Simple qw/use_weak_refs/; use Tree::Simple::Visitor::FindByUID; use attributes; +use YAML (); __PACKAGE__->mk_accessors( qw/counter request response state action stack namespace/ @@ -571,11 +572,21 @@ sub setup { } } + $class->setup_home( delete $flags->{home} ); + + # YAML config support + my $confpath = + $class->path_to( + Catalyst::Utils::appprefix( ref $class || $class ) . '.yml' ); + my $conf = {}; + $conf = YAML::LoadFile($confpath) if -f $confpath; + my $oldconf = $class->config; + $class->config( { %$oldconf, %$conf } ); + $class->setup_log( delete $flags->{log} ); $class->setup_plugins( delete $flags->{plugins} ); $class->setup_dispatcher( delete $flags->{dispatcher} ); $class->setup_engine( delete $flags->{engine} ); - $class->setup_home( delete $flags->{home} ); for my $flag ( sort keys %{$flags} ) { diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 66a96ff..d965711 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -82,6 +82,7 @@ sub mk_app { if ($gen_app) { $self->_mk_dirs; + $self->_mk_config; $self->_mk_appclass; $self->_mk_readme; $self->_mk_changes; @@ -354,6 +355,14 @@ sub _mk_makefile { } } +sub _mk_config { + my $self = shift; + my $dir = $self->{dir}; + my $appprefix = $self->{appprefix}; + $self->render_file( 'config', + File::Spec->catfile( $dir, "$appprefix.yml" ) ); +} + sub _mk_readme { my $self = shift; my $dir = $self->{dir}; @@ -533,11 +542,6 @@ use Catalyst qw/-Debug Static::Simple/; our $VERSION = '0.01'; # -# Configure the application -# -__PACKAGE__->config( name => '[% name %]' ); - -# # Start the application # __PACKAGE__->setup; @@ -611,6 +615,9 @@ catalyst; install_script glob('script/*.pl'); auto_install; WriteAll; +__config__ +--- +name: [% name %] __readme__ Run script/[% appprefix %]_server.pl to test the application. __changes__