8fcd47b6f7d51d027603acae6d18bb6829175d71
[catagits/CatalystX-DynamicComponent.git] / lib / DynamicAppDemo / ControllerBase.pm
1 package DynamicAppDemo::ControllerBase;
2 use Moose;
3 use Moose::Util qw/find_meta/;
4 use namespace::autoclean;
5
6 # You need attributes still for _DISPATCH and friends.
7 BEGIN { extends 'Catalyst::Controller' }
8
9 sub get_reflected_action_methods {
10     my ($self) = @_;
11     my $meta = find_meta($self);
12
13     return  map { $self->_smash_method_attributes($_) }
14             grep { ! /^(_|new|meta)/ }
15             $meta->get_method_list;
16 }
17
18 # EPIC CHEAT to just smash the attribute definition :)
19 sub _smash_method_attributes {
20     my ($self, $name) = @_;
21     my $meta = find_meta($self);
22
23     my $m = $meta->get_method($name);
24     $m->meta->get_attribute('attributes')->set_value($m, ['Local']);
25     return $m;
26 }
27
28 around get_action_methods => sub {
29     my $orig = shift;
30     my $self = shift;
31     
32     return ($self->get_reflected_action_methods, $self->$orig(@_));
33 };
34
35 __PACKAGE__->meta->make_immutable;
36