X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=a0f4e756da3596d92ee40eac73532190532b9f6a;hb=d09eb4339b4d37a6bb51f837d0ea02f3c26f4486;hp=fa0ebdf703be058263f5e0d7326f8aebe7ed292f;hpb=0bf7ab7160f4f2fd0f00cd3d53ac311e9ad50241;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index fa0ebdf..a0f4e75 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -64,7 +64,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.7099_01'; +our $VERSION = '5.7099_03'; sub import { my ( $class, @arguments ) = @_; @@ -98,7 +98,7 @@ documentation and tutorials. catalyst.pl MyApp # add models, views, controllers - script/myapp_create.pl model MyDatabase DBIC::Schema create=dynamic dbi:SQLite:/path/to/db + script/myapp_create.pl model MyDatabase DBIC::Schema create=static dbi:SQLite:/path/to/db script/myapp_create.pl view MyTemplate TT script/myapp_create.pl controller Search @@ -452,10 +452,16 @@ sub _comp_search_prefixes { # regexp fallback $query = qr/$name/i; - @result = grep { $eligible{ $_ } =~ m{$query} } keys %eligible; + @result = map { $c->components->{ $_ } } grep { $eligible{ $_ } =~ m{$query} } keys %eligible; + + # no results? try against full names + if( !@result ) { + @result = map { $c->components->{ $_ } } grep { m{$query} } keys %eligible; + } # don't warn if we didn't find any results, it just might not exist if( @result ) { + $c->log->warn( qq(Found results for "${name}" using regexp fallback.) ); $c->log->warn( 'Relying on the regexp fallback behavior for component resolution is unreliable and unsafe.' ); $c->log->warn( 'If you really want to search, pass in a regexp as the argument.' ); } @@ -525,7 +531,7 @@ Gets a L instance by name. Any extra arguments are directly passed to ACCEPT_CONTEXT. If the name is omitted, it will look for - - a model object in $c->stash{current_model_instance}, then + - a model object in $c->stash->{current_model_instance}, then - a model name in $c->stash->{current_model}, then - a config setting 'default_model', or - check if there is only one model, and return it if that's the case. @@ -578,7 +584,7 @@ Gets a L instance by name. Any extra arguments are directly passed to ACCEPT_CONTEXT. If the name is omitted, it will look for - - a view object in $c->stash{current_view_instance}, then + - a view object in $c->stash->{current_view_instance}, then - a view name in $c->stash->{current_view}, then - a config setting 'default_view', or - check if there is only one view, and return it if that's the case. @@ -677,11 +683,13 @@ sub component { if( !ref $name ) { # is it the exact name? - return $comps->{ $name } if exists $comps->{ $name }; + return $c->_filter_component( $comps->{ $name }, @args ) + if exists $comps->{ $name }; # perhaps we just omitted "MyApp"? my $composed = ( ref $c || $c ) . "::${name}"; - return $comps->{ $composed } if exists $comps->{ $composed }; + return $c->_filter_component( $comps->{ $composed }, @args ) + if exists $comps->{ $composed }; # search all of the models, views and controllers my( $comp ) = $c->_comp_search_prefixes( $name, qw/Model M Controller C View V/ ); @@ -692,12 +700,13 @@ sub component { my $query = ref $name ? $name : qr{$name}i; my @result = grep { m{$query} } keys %{ $c->components }; - return @result if ref $name; + return map { $c->_filter_component( $_, @args ) } @result if ref $name; if( $result[ 0 ] ) { + $c->log->warn( qq(Found results for "${name}" using regexp fallback.) ); $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' ); $c->log->warn( 'is unreliable and unsafe. You have been warned' ); - return $result[ 0 ]; + return $c->_filter_component( $result[ 0 ], @args ); } # I would expect to return an empty list here, but that breaks back-compat @@ -960,23 +969,75 @@ EOF $class->setup_finished(1); } +=head2 $c->uri_for( $action, \@captures?, @args?, \%query_values? ) + =head2 $c->uri_for( $path, @args?, \%query_values? ) -Merges path with C<< $c->request->base >> for absolute URIs and with -C<< $c->namespace >> for relative URIs, then returns a normalized L -object. If any args are passed, they are added at the end of the path. -If the last argument to C is a hash reference, it is assumed to -contain GET parameter key/value pairs, which will be appended to the URI -in standard fashion. +=over + +=item $action + +A Catalyst::Action object representing the Catalyst action you want to +create a URI for. To get one for an action in the current controller, +use C<< $c->action('someactionname') >>. To get one from different +controller, fetch the controller using C<< $c->controller() >>, then +call C on it. + +This method must be used to create URIs for +L actions. + +=item $path + +The actual path you wish to create a URI for, this is a public path, +not a private action path. + +=item \@captures + +If provided, this argument is used to insert values into a I +action in the parts where the definitions contain I. If +not needed, leave out this argument. -Note that uri_for is destructive to the passed hashref. Subsequent calls -with the same hashref may have unintended results. +=item @args -Instead of C<$path>, you can also optionally pass a C<$action> object -which will be resolved to a path using -C<< $c->dispatcher->uri_for_action >>; if the first element of -C<@args> is an arrayref it is treated as a list of captures to be passed -to C. +If provided, this is used as a list of further path sections to append +to the URI. In a I action these are the equivalent to the +endpoint L. + +=item \%query_values + +If provided, the query_values hashref is used to add query parameters +to the URI, with the keys as the names, and the values as the values. + +=back + +Returns a L object. + + ## Ex 1: a path with args and a query parameter + $c->uri_for('user/list', 'short', { page => 2}); + ## -> ($c->req->base is 'http://localhost:3000/' + URI->new('http://localhost:3000/user/list/short?page=2) + + ## Ex 2: a chained view action that captures the user id + ## In controller: + sub user : Chained('/'): PathPart('myuser'): CaptureArgs(1) {} + sub viewuser : Chained('user'): PathPart('view') {} + + ## In uri creating code: + my $uaction = $c->controller('Users')->action_for('viewuser'); + $c->uri_for($uaction, [ 42 ]); + ## outputs: + URI->new('http://localhost:3000/myuser/42/view') + +Creates a URI object using C<< $c->request->base >> and a path. If an +Action object is given instead of a path, the path is constructed +using C<< $c->dispatcher->uri_for_action >> and passing it the +@captures array, if supplied. + +If any query parameters are passed they are added to the end of the +URI in the usual way. + +Note that uri_for is destructive to the passed query values hashref. +Subsequent calls with the same hashref may have unintended results. =cut @@ -1906,6 +1967,11 @@ search paths, specify a key named C as an array reference. Items in the array beginning with C<::> will have the application class name prepended to them. +All components found will also have any +L loaded and set up as components. +Note, that modules which are B an I of the main +file namespace loaded will not be instantiated as components. + =cut sub setup_components {