Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created August 10, 2009 10:57
Show Gist options
  • Save taiyoh/165131 to your computer and use it in GitHub Desktop.
Save taiyoh/165131 to your computer and use it in GitHub Desktop.
diff --git a/lib/Ark/Action.pm b/lib/Ark/Action.pm
index e6565b3..5dd972c 100644
--- a/lib/Ark/Action.pm
+++ b/lib/Ark/Action.pm
@@ -21,6 +21,14 @@ has controller => (
no Mouse;
+do {
+ my %contained_action_class;
+
+ sub is_contained {
+ return $contained_action_class{ $_[0]->name }++ ? 1 : 0;
+ }
+};
+
sub match {
my ($self, $req) = @_;
diff --git a/lib/Ark/Controller.pm b/lib/Ark/Controller.pm
index 0357dec..fa25a99 100644
--- a/lib/Ark/Controller.pm
+++ b/lib/Ark/Controller.pm
@@ -124,4 +124,9 @@ sub _parse_PathPart_attr {
return PathPart => $value;
}
+sub _parse_ActionClass_attr {
+ my ($self, $name, $value) = @_;
+ return ActionClass => $value;
+}
+
1;
diff --git a/lib/Ark/Core.pm b/lib/Ark/Core.pm
index 7a9f560..76b5fc4 100644
--- a/lib/Ark/Core.pm
+++ b/lib/Ark/Core.pm
@@ -499,6 +499,7 @@ sub register_actions {
controller => $controller,
));
}
+
}
sub register_action {
@@ -508,6 +509,17 @@ sub register_action {
$type->register($action);
}
+ if ( !$action->is_contained and my $classes = $action->attributes->{ActionClass} ) {
+ for (@$classes) {
+ my $ac_class = $_;
+ $ac_class = "Ark::ActionClass::${ac_class}" unless $ac_class =~ s{^\+}{};
+ $self->ensure_class_loaded($ac_class);
+ Mouse::Util::apply_all_roles( 'Ark::Controller', $ac_class );
+ $action->controller->meta->add_around_method_modifier(
+ $action->name => $ac_class->can('execute') );
+ }
+ }
+
my $container = $self->actions->{ $action->namespace }
||= Ark::ActionContainer->new( namespace => $action->namespace );
$container->actions->{ $action->name } = $action;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment