summaryrefslogtreecommitdiffstats
path: root/lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm')
-rw-r--r--lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm b/lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm
new file mode 100644
index 0000000..1df9d3e
--- /dev/null
+++ b/lib/IM/Engine/Plugin/Commands/Trait/Class/Command.pm
@@ -0,0 +1,33 @@
+package IM::Engine::Plugin::Commands::Trait::Class::Command;
+use Moose::Role;
+
+after ((map { "add_${_}_method_modifier" } qw/before after around/) => sub {
+ my $self = shift;
+ my $name = shift;
+
+ my $method_meta = $self->get_method($name);
+ my $orig_method_meta = $method_meta->get_original_method;
+ return unless $orig_method_meta->meta->can('does_role')
+ && $orig_method_meta->meta->does_role('IM::Engine::Plugin::Commands::Trait::Method::Command');
+ my $pass_args = $orig_method_meta->pass_args;
+ my $method_metaclass = Moose::Meta::Class->create_anon_class(
+ superclasses => [blessed $method_meta],
+ roles => ['IM::Engine::Plugin::Commands::Trait::Method::Command'],
+ cache => 1,
+ );
+ $method_metaclass->rebless_instance($method_meta, pass_args => $pass_args);
+});
+
+sub get_command {
+ my $self = shift;
+ my ($action) = @_;
+ my $method_meta = $self->find_method_by_name($action);
+ return $method_meta
+ if blessed($method_meta)
+ && $method_meta->meta->can('does_role')
+ && $method_meta->meta->does_role('IM::Engine::Plugin::Commands::Trait::Method::Command');
+}
+
+no Moose::Role;
+
+1;