X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=d93707fcd26f0c6c52b191687f125f150d1fedb0;hp=5a91f46a92299f68f6de8ece7cba7333b465d217;hb=8327e2e21fc9ea72c357e876f868001ad9712474;hpb=c0f74851f0f37dd24be65f03ad29f71fb642db99 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 5a91f46..d93707f 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -21,8 +21,6 @@ use Scalar::Util qw/weaken/; use Tree::Simple qw/use_weak_refs/; use Tree::Simple::Visitor::FindByUID; use attributes; -use YAML::Syck; -use File::Slurp; __PACKAGE__->mk_accessors( qw/counter request response state action stack namespace/ @@ -49,11 +47,11 @@ our $DETACH = "catalyst_detach\n"; require Module::Pluggable::Fast; # Helper script generation -our $CATALYST_SCRIPT_GEN = 26; +our $CATALYST_SCRIPT_GEN = 27; __PACKAGE__->mk_classdata($_) for qw/components arguments dispatcher engine log dispatcher_class - engine_class context_class request_class response_class/; + engine_class context_class request_class response_class setup_finished/; __PACKAGE__->dispatcher_class('Catalyst::Dispatcher'); __PACKAGE__->engine_class('Catalyst::Engine::CGI'); @@ -373,7 +371,7 @@ sub component { if ( exists $c->components->{$try} ) { my $comp = $c->components->{$try}; - if ( ref $comp && $comp->can('ACCEPT_CONTEXT') ) { + if ( eval { $comp->can('ACCEPT_CONTEXT'); } ) { return $comp->ACCEPT_CONTEXT($c); } else { return $comp } @@ -447,14 +445,25 @@ sub view { Returns or takes a hashref containing the application's configuration. - __PACKAGE__->config({ db => 'dsn:SQLite:foo.db' }); + __PACKAGE__->config( { db => 'dsn:SQLite:foo.db' } ); -You can also use a L config file like myapp.json in your +You can also use a L config file like myapp.yml in your applications home directory. --- db: dsn:SQLite:foo.db +=cut + +sub config { + my $c = shift; + + $c->log->warn("Setting config after setup has been run is not a good idea.") + if ( @_ and $c->setup_finished ); + + $c->NEXT::config(@_); +} + =head2 $c->debug Overload to enable debug messages (same as -Debug option). @@ -591,18 +600,6 @@ 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 = {}; - if ( -f $confpath ) { - my $content = read_file("$confpath"); - $conf = YAML::Syck::Load($content); - } - 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} ); @@ -692,6 +689,8 @@ EOF $class->log->info("$name powered by Catalyst $Catalyst::VERSION"); } $class->log->_flush() if $class->log->can('_flush'); + + $class->setup_finished(1); } =head2 $c->uri_for( $path, [ @args ] ) @@ -718,12 +717,15 @@ sub uri_for { $namespace = '' if $path =~ /^\//; $path =~ s/^\///; + my $params = (scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {}); + # join args with '/', or a blank string my $args = ( scalar @args ? '/' . join( '/', @args ) : '' ); $args =~ s/^\/// unless $path; my $res = URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base ) ->canonical; + $res->query_form(%$params); $res; } @@ -1584,7 +1586,7 @@ sub setup_components { } Catalyst::Exception->throw( message => -qq/Couldn't instantiate component "$component", "new() didn't return a object"/ +qq/Couldn't instantiate component "$component", "COMPONENT() didn't return a object"/ ) unless ref $instance; return $instance;