package Catalyst::Controller;
use Moose;
-use Moose::Util qw/find_meta does_role/;
+use Moose::Util qw/find_meta/;
use namespace::clean -except => 'meta';
package MyApp::Controller::Search
use base qw/Catalyst::Controller/;
- sub foo : Local {
+ sub foo : Local {
my ($self,$c,@args) = @_;
- ...
+ ...
} # Dispatches to /search/foo
=head1 DESCRIPTION
return $app->dispatcher->get_action($name, $self->action_namespace);
}
-#my opinion is that this whole sub really should be a builder method, not
+#my opinion is that this whole sub really should be a builder method, not
#something that happens on every call. Anyone else disagree?? -- groditi
## -- apparently this is all just waiting for app/ctx split
around action_namespace => sub {
return $namespace;
};
+sub get_action_methods {
+ my $self = shift;
+ my $meta = find_meta($self);
+ confess("Metaclass for " . ref($meta) ." for " . $meta->name
+ . " cannot support register_actions.")
+ unless $meta->can('get_all_methods_with_attributes');
+ my @methods = $meta->get_all_methods_with_attributes;
+ return @methods;
+}
sub register_actions {
my ( $self, $c ) = @_;
+ $self->register_action_methods( $c, $self->get_action_methods );
+}
+
+sub register_action_methods {
+ my ( $self, $c, @methods ) = @_;
my $class = ref $self || $self;
#this is still not correct for some reason.
my $namespace = $self->action_namespace($c);
- my $meta = find_meta($self);
- my @methods = grep { does_role($_, 'MooseX::MethodAttributes::Role::Meta::Method') }
- $meta->get_all_methods;
foreach my $method (@methods) {
my $name = $method->name;
my $prefix = $self->path_prefix( $c );
$prefix .= '/' if length( $prefix );
-
+
return ( 'Regex', "^${prefix}${value}" );
}
will be bound to 'foo/bar'. The default Root controller is an example
of setting namespace to '' (the null string).
-=head2 path
+=head2 path
Sets 'path_prefix', as described below.