X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=f74fa734ccb5fb8d95787a50394ad09f5db4e2a7;hb=3e93ee3b67452c2c7f1af70be3a91e2784320576;hp=257a8cd3f71c9221ea7bd04fc65c8072249c9bea;hpb=91571b7b15fd05fbcb7014a274dc1f03c34e68be;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 257a8cd..f74fa73 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -80,18 +80,24 @@ Regex search for a component. =cut sub component { - my ( $c, $name ) = @_; + my $c = shift; - if ( my $component = $c->components->{$name} ) { - return $component; - } + if ( @_ ) { - else { - for my $component ( keys %{ $c->components } ) { - return $c->components->{$component} if $component =~ /$name/i; + my $name = shift; + + if ( my $component = $c->components->{$name} ) { + return $component; + } + + else { + for my $component ( keys %{ $c->components } ) { + return $c->components->{$component} if $component =~ /$name/i; + } } } + return sort keys %{ $c->components }; } =item $c->error @@ -193,10 +199,6 @@ sub finalize { return $status; } -=item $c->finalize_output - -alias to finalize_body - =item $c->finalize_body Finalize body. @@ -364,7 +366,7 @@ sub handler { my $elapsed; ( $elapsed, $status ) = $class->benchmark($handler); $elapsed = sprintf '%f', $elapsed; - my $av = sprintf '%.3f', 1 / $elapsed; + my $av = sprintf '%.3f', ( $elapsed == 0 ? '??' : (1 / $elapsed) ); my $t = Text::ASCIITable->new; $t->setCols( 'Action', 'Time' ); $t->setColWidth( 'Action', 64, 1 ); @@ -387,7 +389,7 @@ sub handler { return $status; } -=item $c->prepare($r) +=item $c->prepare($engine) Turns the engine-specific request( Apache, CGI ... ) into a Catalyst context . @@ -404,12 +406,18 @@ sub prepare { cookies => {}, headers => HTTP::Headers->new, parameters => {}, + secure => 0, snippets => [], uploads => {} } ), response => Catalyst::Response->new( - { cookies => {}, headers => HTTP::Headers->new, status => 200 } + { + body => '', + cookies => {}, + headers => HTTP::Headers->new, + status => 200 + } ), stash => {}, state => 0 @@ -425,10 +433,10 @@ sub prepare { } $c->prepare_request($engine); - $c->prepare_path; + $c->prepare_connection; $c->prepare_headers; $c->prepare_cookies; - $c->prepare_connection; + $c->prepare_path; $c->prepare_action; my $method = $c->req->method || ''; @@ -462,8 +470,9 @@ sub prepare { $t->setCols( 'Key', 'Value' ); $t->setColWidth( 'Key', 37, 1 ); $t->setColWidth( 'Value', 36, 1 ); - for my $key ( keys %{ $c->req->params } ) { - my $value = $c->req->params->{$key} || ''; + for my $key ( sort keys %{ $c->req->params } ) { + my $param = $c->req->params->{$key}; + my $value = defined($param) ? $param : ''; $t->addRow( $key, $value ); } $c->log->debug( 'Parameters are', $t->draw ); @@ -592,6 +601,35 @@ Prepare uploads. sub prepare_uploads { } +=item $c->retrieve_components + +Retrieve Components. + +=cut + +sub retrieve_components { + my $self = shift; + + my $class = ref $self || $self; + eval <<""; + package $class; + import Module::Pluggable::Fast + name => '_components', + search => [ + '$class\::Controller', '$class\::C', + '$class\::Model', '$class\::M', + '$class\::View', '$class\::V' + ], + require => 1; + + if ( my $error = $@ ) { + chomp $error; + die qq/Couldn't load components "$error"/; + } + + return $self->_components; +} + =item $c->run Starts the engine. @@ -669,7 +707,7 @@ sub setup_components { my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } ); $t->setCols('Class'); $t->setColWidth( 'Class', 75, 1 ); - $t->addRow($_) for keys %{ $self->components }; + $t->addRow($_) for sort keys %{ $self->components }; $self->log->debug( 'Loaded components', $t->draw ) if ( @{ $t->{tbl_rows} } && $self->debug ); @@ -691,8 +729,8 @@ Returns a hashref containing all your data. sub stash { my $self = shift; - if ( $_[0] ) { - my $stash = $_[1] ? {@_} : $_[0]; + if ( @_ ) { + my $stash = @_ > 1 ? {@_} : $_[0]; while ( my ( $key, $val ) = each %$stash ) { $self->{stash}->{$key} = $val; }