This file documents the revision history for Perl extension Catalyst.
+ - added Catalyst::Base->action_for('methodname')
- checked and tested :Args multimethod dispatch
- added ability to set action attributes from controller config
- added merge_config_hashes() as a convenience method
return !@{ $c->error };
}
+sub new {
+ my $self = shift;
+ my $app = $_[0];
+ my $new = $self->NEXT::new(@_);
+ $new->{application} = $app;
+ return $new;
+}
+
=head1 NAME
Catalyst::Base - Catalyst Base Class
=head1 METHODS
+=head2 $self->action_for('name')
+
+Returns the Catalyst::Action object (if any) for a given method name in
+this component.
+
+=cut
+
+sub action_for {
+ my ( $self, $name ) = @_;
+ my $app = ($self->isa('Catalyst') ? $self : $self->{application});
+ return $app->dispatcher->get_action($name, $self->action_namespace);
+}
+
=head2 $self->action_namespace($c)
Returns the private namespace for actions in this component. Defaults to a value
sub action_namespace {
my ( $self, $c ) = @_;
+ unless ( $c ) {
+ $c = ($self->isa('Catalyst') ? $self : $self->{application});
+ }
my $hash = (ref $self ? $self : $self->config); # hate app-is-class
return $hash->{namespace} if exists $hash->{namespace};
return Catalyst::Utils::class2prefix( ref($self) || $self,
sub path_prefix {
my ( $self, $c ) = @_;
+ unless ( $c ) {
+ $c = ($self->isa('Catalyst') ? $self : $self->{application});
+ }
my $hash = (ref $self ? $self : $self->config); # hate app-is-class
return $hash->{path} if exists $hash->{path};
return shift->action_namespace(@_);
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More;
+
+plan tests => 3;
+
+use_ok('TestApp');
+
+is(TestApp->action_for('global_action')->code, TestApp->can('global_action'),
+ 'action_for on appclass ok');
+
+is(TestApp->controller('Args')->action_for('args')->code,
+ TestApp::Controller::Args->can('args'),
+ 'action_for on controller ok');