X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=8d5113e09ceaf8eba1063fdc16b49b1e6a7f6d41;hp=44dd8e62a00efd06b53c0f71123bd8c3f9011258;hb=36c67dc10cd5a928718d4e9122e03297a959a47e;hpb=83b8cda15c8813eb706987fbc9345a4cf79a8b44 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 44dd8e6..8d5113e 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -79,7 +79,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.80012'; +our $VERSION = '5.80013'; { my $dev_version = $VERSION =~ /_\d{2}$/; @@ -349,6 +349,21 @@ Or make sure to always return true values from your actions and write your code like this: $c->forward('foo') || return; + +Another note is that C<< $c->forward >> always returns a scalar because it +actually returns $c->state which operates in a scalar context. +Thus, something like: + + return @array; + +in an action that is forwarded to is going to return a scalar, +i.e. how many items are in that array, which is probably not what you want. +If you need to return an array then return a reference to it, +or stash it like so: + + $c->stash->{array} = \@array; + +and access it from the stash. =cut @@ -403,12 +418,15 @@ sub visit { my $c = shift; $c->dispatcher->visit( $c, @_ ) } =head2 $c->go( $class, $method, [, \@captures, \@arguments ] ) -Almost the same as L<< detach|/"$c->detach( $action [, \@arguments ] )" >>, but does a full dispatch like L, -instead of just calling the new C<$action> / -C<< $class->$method >>. This means that C, C and the -method you visit are called, just like a new request. - -C<< $c->stash >> is kept unchanged. +The relationship between C and +L<< visit|/"$c->visit( $action [, \@captures, \@arguments ] )" >> is the same as +the relationship between +L<< forward|/"$c->forward( $class, $method, [, \@arguments ] )" >> and +L<< detach|/"$c->detach( $action [, \@arguments ] )" >>. Like C<< $c->visit >>, +C<< $c->go >> will perform a full dispatch on the specified action or method, +with localized C<< $c->action >> and C<< $c->namespace >>. Like C, +C escapes the processing of the current request chain on completion, and +does not return to its caller. =cut @@ -487,7 +505,9 @@ sub error { =head2 $c->state -Contains the return value of the last executed action. +Contains the return value of the last executed action. +Note that << $c->state >> operates in a scalar context which means that all +values it returns are scalar. =head2 $c->clear_errors @@ -532,6 +552,10 @@ sub _comp_names_search_prefixes { # if we were given a regexp to search against, we're done. return if ref $name; + # skip regexp fallback if configured + return + if $appclass->config->{disable_component_resolution_regex_fallback}; + # regexp fallback $query = qr/$name/i; @result = grep { $eligible{ $_ } =~ m{$query} } keys %eligible; @@ -549,7 +573,8 @@ sub _comp_names_search_prefixes { (join '", "', @result) . "'. Relying on regexp fallback behavior for " . "component resolution is unreliable and unsafe."; my $short = $result[0]; - $short =~ s/.*?Model:://; + # remove the component namespace prefix + $short =~ s/.*?(Model|Controller|View):://; my $shortmess = Carp::shortmess(''); if ($shortmess =~ m#Catalyst/Plugin#) { $msg .= " You probably need to set '$short' instead of '${name}' in this " . @@ -558,7 +583,7 @@ sub _comp_names_search_prefixes { $msg .= " You probably need to set '$short' instead of '${name}' in this " . "component's config"; } else { - $msg .= " You probably meant \$c->${warn_for}('$short') instead of \$c->${warn_for}({'${name}'}), " . + $msg .= " You probably meant \$c->${warn_for}('$short') instead of \$c->${warn_for}('${name}'), " . "but if you really wanted to search, pass in a regexp as the argument " . "like so: \$c->${warn_for}(qr/${name}/)"; } @@ -775,6 +800,12 @@ should be used instead. If C<$name> is a regexp, a list of components matched against the full component name will be returned. +If Catalyst can't find a component by name, it will fallback to regex +matching by default. To disable this behaviour set +disable_component_resolution_regex_fallback to a true value. + + __PACKAGE__->config( disable_component_resolution_regex_fallback => 1 ); + =cut sub component { @@ -1136,7 +1167,6 @@ EOF } $meta->make_immutable( replace_constructor => 1, - allow_mutable_ancestors => 1, ) unless $meta->is_immutable; }; @@ -1217,9 +1247,10 @@ sub uri_for { } if ( blessed($path) ) { # action object - my $captures = ( scalar @args && ref $args[0] eq 'ARRAY' - ? shift(@args) - : [] ); + my $captures = [ map { s|/|%2F|; $_; } + ( scalar @args && ref $args[0] eq 'ARRAY' + ? @{ shift(@args) } + : ()) ]; my $action = $path; $path = $c->dispatcher->uri_for_action($action, $captures); if (not defined $path) { @@ -1237,6 +1268,7 @@ sub uri_for { carp "uri_for called with undef argument" if grep { ! defined $_ } @args; s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args; + s|/|%2F| for @args; unshift(@args, $path); @@ -1599,9 +1631,10 @@ sub _stats_start_execute { # is this a root-level call or a forwarded call? if ( $callsub =~ /forward$/ ) { + my $parent = $c->stack->[-1]; # forward, locate the caller - if ( my $parent = $c->stack->[-1] ) { + if ( exists $c->counter->{"$parent"} ) { $c->stats->profile( begin => $action, parent => "$parent" . $c->counter->{"$parent"}, @@ -2633,6 +2666,77 @@ messages in template systems. sub version { return $Catalyst::VERSION } +=head1 CONFIGURATION + +There are a number of 'base' config variables which can be set: + +=over + +=item * + +C - Makes private paths case sensitive. See L. + +=item * + +C - The default model picked if you say C<< $c->model >>. See Lmodel($name)>. + +=item * + +C - The default view to be rendered or returned when C<< $c->view >>. See Lview($name)>. +is called. + +=item * + +C - Turns +off the deprecated component resolution functionality so +that if any of the component methods (e.g. C<< $c->controller('Foo') >>) +are called then regex search will not be attempted on string values and +instead C will be returned. + +=item * + +C - The application home directory. In an uninstalled application, +this is the top level application directory. In an installed application, +this will be the directory containing C<< MyApp.pm >>. + +=item * + +C - See L + +=item * + +C - The name of the application in debug messages and the debug and +welcome screens + +=item * + +C - The request body (for example file uploads) will not be parsed +until it is accessed. This allows you to (for example) check authentication (and reject +the upload) before actually recieving all the data. See L + +=item * + +C - The root directory for templates. Usually this is just a +subdirectory of the home directory, but you can set it to change the +templates to a different directory. + +=item * + +C - Array reference passed to Module::Pluggable to for additional +namespaces from which components will be loaded (and constructed and stored in +C<< $c->components >>). + +=item * + +C - If true, causes internal actions such as C<< _DISPATCH >> +to be shown in hit debug tables in the test server. + +=item * + +C - See L. + +=back + =head1 INTERNAL ACTIONS Catalyst uses internal actions like C<_DISPATCH>, C<_BEGIN>, C<_AUTO>, @@ -2760,6 +2864,8 @@ abw: Andy Wardley acme: Leon Brocard +abraxxa: Alexander Hartmaier + Andrew Bramble Andrew Ford EA.Ford@ford-mason.co.ukE