support hashref for params in uri_for
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 8ed0016..d93707f 100644 (file)
@@ -47,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');
@@ -447,6 +447,23 @@ Returns or takes a hashref containing the application's configuration.
 
     __PACKAGE__->config( { db => 'dsn:SQLite:foo.db' } );
 
+You can also use a L<YAML> 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).
@@ -672,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 ] )
@@ -698,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;
 }