X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=38d8aeffbaa6fe99c25269b702c32e4b00584f68;hb=b6898a9f489a6e5946a4640ec049ada70f47a48a;hp=4d25d70f5dc1384ffef6211fec8e58c06a95fcec;hpb=7e5adeddb832463a4c4028b4ea2ec9fdf1ddbdad;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 4d25d70..38d8aef 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -37,9 +37,15 @@ See L. =head1 DESCRIPTION -=head2 METHODS +=head1 METHODS -=head3 action +=over 4 + +=item $c->action( $name => $coderef, ... ) + +=item $c->action( $name ) + +=item $c->action Add one or more actions. @@ -94,9 +100,8 @@ sub action { if ( my $p = $self->actions->{plain}->{$action} ) { return [$p] } elsif ( my $r = $self->actions->{regex}->{$action} ) { return [$r] } else { - while ( my ( $regex, $name ) = - each %{ $self->actions->{compiled} } ) - { + for my $regex ( keys %{ $self->actions->{compiled} } ) { + my $name = $self->actions->{compiled}->{$regex}; if ( $action =~ $regex ) { my @snippets; for my $i ( 1 .. 9 ) { @@ -119,7 +124,7 @@ sub action { } } -=head3 benchmark +=item $c->benchmark($coderef) Takes a coderef with arguments and returns elapsed time as float. @@ -137,7 +142,9 @@ sub benchmark { return wantarray ? ( $elapsed, @return ) : $elapsed; } -=head3 component (comp) +=item $c->comp($name) + +=item $c->component($name) Get a component object by name. @@ -161,7 +168,11 @@ sub component { } } -=head3 errors +=item $c->errors + +=item $c->errors($error, ...) + +=item $c->errors($arrayref) Returns an arrayref containing errors messages. @@ -180,7 +191,7 @@ sub errors { return $c->{errors}; } -=head3 finalize +=item $c->finalize Finalize request. @@ -188,6 +199,13 @@ Finalize request. sub finalize { my $c = shift; + + if ( my $location = $c->res->redirect ) { + $c->log->debug(qq/Redirecting to "$location"/) if $c->debug; + $c->res->headers->header( Location => $location ); + $c->res->status(302); + } + if ( !$c->res->output || $#{ $c->errors } >= 0 ) { $c->res->headers->content_type('text/html'); my $name = $c->config->{name} || 'Catalyst Application'; @@ -281,18 +299,13 @@ sub finalize { } - if ( my $location = $c->res->redirect ) { - $c->log->debug(qq/Redirecting to "$location"/) if $c->debug; - $c->res->headers->header( Location => $location ); - $c->res->status(302); - } $c->res->headers->content_length( length $c->res->output ); my $status = $c->finalize_headers; $c->finalize_output; return $status; } -=head3 finalize_headers +=item $c->finalize_headers Finalize headers. @@ -300,7 +313,7 @@ Finalize headers. sub finalize_headers { } -=head3 finalize_output +=item $c->finalize_output Finalize output. @@ -308,7 +321,7 @@ Finalize output. sub finalize_output { } -=head3 forward +=item $c->forward($command) Forward processing to a private/public action or a method from a class. If you define a class without method it will default to process(). @@ -374,7 +387,7 @@ sub forward { return $c->process( $class, $code ); } -=head3 handler +=item $c->handler($r) Handles the request. @@ -441,9 +454,9 @@ sub handler { return $status; } -=head3 prepare +=item $c->prepare($r) -Turns the request (Apache, CGI...) into a Catalyst context. +Turns the engine-specific request (Apache, CGI...) into a Catalyst context. =cut @@ -475,17 +488,31 @@ sub prepare { } $c->prepare_request($r); $c->prepare_path; - my $path = $c->request->path; - $c->log->debug(qq/Requested path "$path"/) if $c->debug; $c->prepare_cookies; $c->prepare_headers; + $c->prepare_connection; + my $method = $c->req->method || ''; + my $path = $c->req->path || ''; + my $hostname = $c->req->hostname || ''; + my $address = $c->req->address || ''; + $c->log->debug(qq/"$method" request for "$path" from $hostname($address)/) + if $c->debug; $c->prepare_action; $c->prepare_parameters; + + if ( $c->debug && keys %{ $c->req->params } ) { + my @params; + for my $key ( keys %{ $c->req->params } ) { + my $value = $c->req->params->{$key} || ''; + push @params, "$key=$value"; + } + $c->log->debug( 'Parameters are "' . join( ' ', @params ) . '"' ); + } $c->prepare_uploads; return $c; } -=head3 prepare_action +=item $c->prepare_action Prepare action. @@ -517,8 +544,6 @@ sub prepare_action { $c->log->debug(qq/Requested action "$path"/) if $c->debug; } $c->req->match($path); - $c->log->debug( 'Arguments are "' . join( '/', @args ) . '"' ) - if ( $c->debug && @args ); last; } unshift @args, pop @path; @@ -536,9 +561,19 @@ sub prepare_action { $c->log->debug('Using default action') if $c->debug; } } + $c->log->debug( 'Arguments are "' . join( '/', @args ) . '"' ) + if ( $c->debug && @args ); } -=head3 prepare_cookies; +=item $c->prepare_connection; + +Prepare connection. + +=cut + +sub prepare_connection { } + +=item $c->prepare_cookies; Prepare cookies. @@ -546,7 +581,7 @@ Prepare cookies. sub prepare_cookies { } -=head3 prepare_headers +=item $c->prepare_headers Prepare headers. @@ -554,7 +589,7 @@ Prepare headers. sub prepare_headers { } -=head3 prepare_parameters +=item $c->prepare_parameters Prepare parameters. @@ -562,7 +597,7 @@ Prepare parameters. sub prepare_parameters { } -=head3 prepare_path +=item $c->prepare_path Prepare path and base. @@ -570,7 +605,7 @@ Prepare path and base. sub prepare_path { } -=head3 prepare_request +=item $c->prepare_request Prepare the engine request. @@ -578,7 +613,7 @@ Prepare the engine request. sub prepare_request { } -=head3 prepare_uploads +=item $c->prepare_uploads Prepare uploads. @@ -586,7 +621,7 @@ Prepare uploads. sub prepare_uploads { } -=head3 process +=item $c->process($class, $coderef) Process a coderef in given class and catch exceptions. Errors are available via $c->errors. @@ -618,7 +653,7 @@ sub process { return $status; } -=head3 remove_action +=item $c->remove_action($action) Remove an action. @@ -641,19 +676,23 @@ sub remove_action { } } -=head3 request (req) +=item $c->request + +=item $c->req Returns a C object. my $req = $c->req; -=head3 response (res) +=item $c->response + +=item $c->res Returns a C object. my $res = $c->res; -=head3 setup +=item $class->setup Setup. @@ -670,7 +709,7 @@ sub setup { } } -=head3 setup_components +=item $class->setup_components Setup components. @@ -706,7 +745,7 @@ sub setup_components { if $self->debug; } -=head3 stash +=item $c->stash Returns a hashref containing all your data. @@ -741,6 +780,8 @@ sub _class2prefix { return $prefix; } +=back + =head1 AUTHOR Sebastian Riedel, C