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/
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 }
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 ) = @_;
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<Catalyst::Model> instance by name.
}
+=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<Catalyst::View> instance by name.
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
<a href="http://lists.rawmode.org/mailman/listinfo/catalyst">Mailing-List</a>
</li>
<li>
- <a href="irc://irc.perl.org/catalyst">IRC channel #catalyst on irc.perl.org</a>
+ <a href="irc://irc.perl.org/catalyst">IRC channel #catalyst-talk on irc.perl.org</a>
</li>
</ul>
<h2>In conclusion</h2>
IRC:
- Join #catalyst on irc.perl.org.
+ Join #catalyst-talk on irc.perl.org.
Mailing Lists: