From: Sebastian Riedel Date: Mon, 30 Jan 2006 16:35:36 +0000 (+0000) Subject: YAML support is back, yay! X-Git-Tag: 5.7099_04~717 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=a6ad13b6d56ddf1fe82277af6b62a7d01bd4e4b0 YAML support is back, yay! --- diff --git a/Changes b/Changes index 164dd33..cdc628e 100644 --- a/Changes +++ b/Changes @@ -1,13 +1,12 @@ This file documents the revision history for Perl extension Catalyst. +5.64 + - Updated YAML support - Fixed path dispatch to canonicalise correctly (see http://dev.catalyst.perl.org/ticket/62) - Added Catalyst::Manual::About -5.64 - - Removed YAML support - -5.63 +5.63 2006-01-22 00:00:00 - Updated prereq versions 5.62 2006-01-17 16:30:00 diff --git a/Makefile.PL b/Makefile.PL index f37fe54..8bd49f1 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -35,6 +35,7 @@ requires 'URI' => 1.35; requires 'File::Copy::Recursive'; requires 'Module::Install::Admin' => '0.54'; requires 'Module::Install' => '0.54'; +requires 'YAML' => '0.55'; feature 'Apache/mod_perl Support', -default => 0, diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 5a1959e..8fedc9c 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -21,6 +21,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/ @@ -447,6 +448,12 @@ Returns or takes a hashref containing the application's configuration. __PACKAGE__->config( { db => 'dsn:SQLite:foo.db' } ); +You can also use a L config file like myapp.yml in your +applications home directory. + + --- + db: dsn:SQLite:foo.db + =cut sub config { @@ -594,6 +601,15 @@ sub setup { $class->setup_home( delete $flags->{home} ); + # YAML config support + my $confpath = $class->config->{file} + || $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} ); diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 8d3fbb7..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__