X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=d75651498db854890d30860fc1e04e150e3ada6b;hp=6b519b444a218ba788526d41c5d3b64ca3cf5bbc;hb=9ce444302fb0d264c4182d57d564e376e61a4725;hpb=5050d7a770f5367adee391568ae7c79cefe8daae diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 6b519b4..d756514 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -22,6 +22,7 @@ use Scalar::Util qw/weaken blessed/; use Tree::Simple qw/use_weak_refs/; use Tree::Simple::Visitor::FindByUID; use attributes; +use Carp qw/croak/; __PACKAGE__->mk_accessors( qw/counter request response state action stack namespace/ @@ -298,6 +299,7 @@ sub error { my $c = shift; if ( $_[0] ) { my $error = ref $_[0] eq 'ARRAY' ? $_[0] : [@_]; + croak @$error unless ref $c; push @{ $c->{error} }, @$error; } elsif ( defined $_[0] ) { $c->{error} = undef } @@ -399,6 +401,29 @@ sub _comp_prefixes { return $comp; } +# Find possible names for a prefix + +sub _comp_names { + my ( $c, @prefixes ) = @_; + + my $appclass = ref $c || $c; + + my @pre = map { "${appclass}::${_}::" } @prefixes; + + my @names; + + COMPONENT: foreach my $comp ($c->component) { + foreach my $p (@pre) { + if ($comp =~ s/^$p//) { + push(@names, $comp); + next COMPONENT; + } + } + } + + return @names; +} + # Return a component if only one matches. sub _comp_singular { my ( $c, @prefixes ) = @_; @@ -475,6 +500,17 @@ sub controller { return $c->component( $c->action->class ); } +=head2 $c->controllers + +Returns the available names which can be passed to $c->controller + +=cut + +sub controllers { + my ( $c ) = @_; + return $c->_comp_names(qw/Controller C/); +} + =head2 $c->model($name) Gets a L instance by name. @@ -497,6 +533,17 @@ sub model { } +=head2 $c->models + +Returns the available names which can be passed to $c->model + +=cut + +sub models { + my ( $c ) = @_; + return $c->_comp_names(qw/Model M/); +} + =head2 $c->view($name) Gets a L instance by name. @@ -518,6 +565,17 @@ sub view { return $c->_filter_component( $c->_comp_singular(qw/View V/) ); } +=head2 $c->views + +Returns the available names which can be passed to $c->view + +=cut + +sub views { + my ( $c ) = @_; + return $c->_comp_names(qw/View V/); +} + =head2 Class data and helper classes =head2 $c->config @@ -767,7 +825,7 @@ EOF $class->setup_finished(1); } -=head2 $c->uri_for( $path, [ @args ] ) +=head2 $c->uri_for( $path, @args?, \%query_values? ) Merges path with C<$c-Erequest-Ebase> for absolute uri's and with C<$c-Enamespace> for relative uri's, then returns a