c0296bb4f386e8866de08869b52c3a201f335f57
[catagits/CatalystX-DynamicComponent.git] / lib / CatalystX / ModelToControllerReflector / ControllerRole.pm
1 package CatalystX::ModelToControllerReflector::ControllerRole;
2 use Moose::Role;
3 use Moose::Util qw/find_meta/;
4 use namespace::autoclean;
5
6 sub get_reflected_action_methods {
7     my ($self) = @_;
8     my $meta = find_meta($self);
9
10     return  map { $self->_smash_method_attributes($_) }
11             grep { ! /^(_|new|meta|get_action_methods)$/ }
12                                         # FIXME - giant turd, right there.
13             $meta->get_method_list;    # we need to apply a role to the
14                                        # metaclass of each method we generate,
15                                        # and then test for that role being done
16                                        # by the method in question here.
17                                         # Should probably also check they supports
18                                         # attributes and shit self if not.
19 }
20
21 # EPIC CHEAT to just smash the attribute definition :)
22 sub _smash_method_attributes {
23     my ($self, $name) = @_;
24     my $meta = find_meta($self);
25
26     my $m = $meta->get_method($name);
27     $m->meta->get_attribute('attributes')->set_value($m, ['Local']);
28     return $m;
29 }
30
31 around get_action_methods => sub {
32     my $orig = shift;
33     my $self = shift;
34
35     return ($self->get_reflected_action_methods, $self->$orig(@_));
36 };
37
38 1;
39