Factor out to smaller routines
t0m [Fri, 24 Apr 2009 22:33:12 +0000 (23:33 +0100)]
lib/DynamicAppDemo/ControllerBase.pm

index 5075b3a..8fcd47b 100644 (file)
@@ -6,27 +6,30 @@ use namespace::autoclean;
 # You need attributes still for _DISPATCH and friends.
 BEGIN { extends 'Catalyst::Controller' }
 
+sub get_reflected_action_methods {
+    my ($self) = @_;
+    my $meta = find_meta($self);
+
+    return  map { $self->_smash_method_attributes($_) }
+            grep { ! /^(_|new|meta)/ }
+            $meta->get_method_list;
+}
+
+# EPIC CHEAT to just smash the attribute definition :)
+sub _smash_method_attributes {
+    my ($self, $name) = @_;
+    my $meta = find_meta($self);
+
+    my $m = $meta->get_method($name);
+    $m->meta->get_attribute('attributes')->set_value($m, ['Local']);
+    return $m;
+}
+
 around get_action_methods => sub {
     my $orig = shift;
     my $self = shift;
-
-    my $meta = find_meta($self);
     
-    # FIXME - fugly, and nasty
-    return (
-        (   map { 
-                my $m = $meta->get_method($_);
-                # EPIC CHEAT to just smash the attribute definition :)
-                $m->meta->get_attribute('attributes')->set_value($m, ['Local']);
-                $m;
-            }
-            grep { ! /^(_|new|meta)/ }
-            $meta->get_method_list
-        ),
-        (
-            $self->$orig(@_)
-        )
-    ); 
+    return ($self->get_reflected_action_methods, $self->$orig(@_));
 };
 
 __PACKAGE__->meta->make_immutable;