update distar url
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 860822e..de488a4 100644 (file)
@@ -53,6 +53,9 @@ use Class::Load 'load_class';
 use Encode 2.21 'decode_utf8', 'encode_utf8';
 use Scalar::Util;
 
+our $VERSION = '5.90128';
+$VERSION =~ tr/_//d;
+
 BEGIN { require 5.008003; }
 
 has stack => (is => 'ro', default => sub { [] });
@@ -68,6 +71,7 @@ has request => (
         my $composed_request_class = $class->composed_request_class;
         return $composed_request_class->new( $self->_build_request_constructor_args);
     },
+    predicate => 'has_request',
     lazy => 1,
 );
 sub _build_request_constructor_args {
@@ -113,6 +117,7 @@ has response => (
         my $composed_response_class = $class->composed_response_class;
         return $composed_response_class->new( $self->_build_response_constructor_args);
     },
+    predicate=>'has_response',
     lazy => 1,
 );
 sub _build_response_constructor_args {
@@ -204,10 +209,6 @@ sub composed_stats_class {
 
 __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
 
-# Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90117';
-$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
-
 sub import {
     my ( $class, @arguments ) = @_;
 
@@ -409,6 +410,10 @@ Returns the current L<Catalyst::Request> object, giving access to
 information about the current client request (including parameters,
 cookies, HTTP headers, etc.). See L<Catalyst::Request>.
 
+There is a predicate method C<has_request> that returns true if the
+request object has been created.  This is something you might need to
+check if you are writing plugins that run before a request is finalized.
+
 =head2 REQUEST FLOW HANDLING
 
 =head2 $c->forward( $action [, \@arguments ] )
@@ -557,6 +562,10 @@ sub go { my $c = shift; $c->dispatcher->go( $c, @_ ) }
 
 Returns the current L<Catalyst::Response> object, see there for details.
 
+There is a predicate method C<has_response> that returns true if the
+request object has been created.  This is something you might need to
+check if you are writing plugins that run before a request is finalized.
+
 =head2 $c->stash
 
 Returns a hashref to the stash, which may be used to store data and pass
@@ -1601,11 +1610,11 @@ sub uri_for {
         $path .= '/';
     }
 
-    my $fragment =  ((scalar(@args) && ref($args[-1]) eq 'SCALAR') ? pop @args : undef );
+    my $fragment =  ((scalar(@args) && ref($args[-1]) eq 'SCALAR') ? ${pop @args} : undef );
 
     unless(blessed $path) {
       if (defined($path) and $path =~ s/#(.+)$//)  {
-        if(defined($1) and $fragment) {
+        if(defined($1) and defined $fragment) {
           carp "Abiguious fragment declaration: You cannot define a fragment in '$path' and as an argument '$fragment'";
         }
         if(defined($1)) {
@@ -1634,14 +1643,15 @@ sub uri_for {
         my $num_captures = $expanded_action->number_of_captures;
 
         # ->uri_for( $action, \@captures_and_args, \%query_values? )
-        if( !@args && $action->number_of_args ) {
+        if( !@args && $action->number_of_args && @$captures > $num_captures ) {
           unshift @args, splice @$captures, $num_captures;
         }
 
         if($num_captures) {
           unless($expanded_action->match_captures_constraints($c, $captures)) {
-            carp "captures [@{$captures}] do not match the type constraints in actionchain ending with '$expanded_action'";
-            return;
+            $c->log->debug("captures [@{$captures}] do not match the type constraints in actionchain ending with '$expanded_action'")
+                if $c->debug;
+            return undef;
           }
         }
 
@@ -1656,8 +1666,9 @@ sub uri_for {
         # At this point @encoded_args is the remaining Args (all captures removed).
         if($expanded_action->has_args_constraints) {
           unless($expanded_action->match_args($c,\@args)) {
-             carp "args [@args] do not match the type constraints in action '$expanded_action'";
-             return;
+             $c->log->debug("args [@args] do not match the type constraints in action '$expanded_action'")
+                if $c->debug;
+             return undef;
           }
         }
     }
@@ -1725,7 +1736,7 @@ sub uri_for {
 
     if(defined $fragment) {
       if(blessed $path) {
-        $fragment = encode_utf8(${$fragment});
+        $fragment = encode_utf8($fragment);
         $fragment =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go;
         $fragment =~ s/ /+/g;
       }
@@ -2194,16 +2205,27 @@ sub finalize {
 
     $c->log_response;
 
-    if ($c->use_stats) {
-        my $elapsed = $c->stats->elapsed;
-        my $av = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
-        $c->log->info(
-            "Request took ${elapsed}s ($av/s)\n" . $c->stats->report . "\n" );
-    }
+    $c->log_stats if $c->use_stats;
 
     return $c->response->status;
 }
 
+=head2 $c->log_stats
+
+Logs statistics.
+
+=cut
+
+sub log_stats {
+    my $c = shift;
+
+    my $elapsed = $c->stats->elapsed;
+    my $av = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
+    $c->log->info(
+        "Request took ${elapsed}s ($av/s)\n" . $c->stats->report . "\n" );
+}
+
+
 =head2 $c->finalize_body
 
 Finalizes body.
@@ -3465,7 +3487,7 @@ sub apply_default_middlewares {
           condition => sub {
               my ($env) = @_;
               return if $app->config->{ignore_frontend_proxy};
-              return $env->{REMOTE_ADDR} eq '127.0.0.1';
+              return $env->{REMOTE_ADDR} && $env->{REMOTE_ADDR} eq '127.0.0.1';
           },
       );
     }
@@ -5009,6 +5031,8 @@ revmischa: Mischa Spiegelmock <revmischa@cpan.org>
 
 Robert Sedlacek <rs@474.at>
 
+rrwo: Robert Rothenberg <rrwo@cpan.org>
+
 SpiceMan: Marcel Montes
 
 sky: Arthur Bergman