X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=34fd2d062d45c0d66c83c2f1c87aeee8c81cabd4;hp=554e959fa737339e2347d7ddbfe9f645ec8b1559;hb=3b88a4556575f18382261e47214bb281694d8f16;hpb=1dafef5544f765f9605b1f02abe54e615d1457ce diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 554e959..34fd2d0 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -399,6 +399,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 +498,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 +531,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 +563,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