diff options
author | doy <doy@tozt.net> | 2009-01-15 21:11:20 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-01-15 21:11:20 -0500 |
commit | 2b478c9e0291e6dc676c654d45098936f0a924cb (patch) | |
tree | 24d2f776d208ebee597ba4560b08cce3f5f14c85 | |
parent | 4f4afc2b22add8c0cbf374fe8b1926393d74b70f (diff) | |
download | bot-games-2b478c9e0291e6dc676c654d45098936f0a924cb.tar.gz bot-games-2b478c9e0291e6dc676c654d45098936f0a924cb.zip |
make Command into a default method metaclass role, and turn the check for whether or not a method is a command into an attribute on the method metaclass
-rw-r--r-- | lib/Bot/Games.pm | 3 | ||||
-rw-r--r-- | lib/Bot/Games/Meta/Attribute.pm | 4 | ||||
-rw-r--r-- | lib/Bot/Games/Meta/Role/Command.pm | 6 | ||||
-rw-r--r-- | lib/Bot/Games/OO.pm | 11 |
4 files changed, 19 insertions, 5 deletions
diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm index 40028fb..854b629 100644 --- a/lib/Bot/Games.pm +++ b/lib/Bot/Games.pm @@ -46,7 +46,8 @@ sub said { my ($action, $arg) = ($1, $2); my $method_meta = $game->meta->find_method_by_name($action); if (blessed $method_meta - && $method_meta->does('Bot::Games::Meta::Role::Command')) { + && $method_meta->does('Bot::Games::Meta::Role::Command') + && $method_meta->command) { $output = $game->$action($arg, {player => $args->{who}}); } else { diff --git a/lib/Bot/Games/Meta/Attribute.pm b/lib/Bot/Games/Meta/Attribute.pm index 47100fd..e6904ee 100644 --- a/lib/Bot/Games/Meta/Attribute.pm +++ b/lib/Bot/Games/Meta/Attribute.pm @@ -20,13 +20,13 @@ after install_accessors => sub { my $self = shift; my $accessor_meta = $self->get_read_method_ref; if ($self->command) { - Moose::Util::apply_all_roles($accessor_meta->meta, 'Bot::Games::Meta::Role::Command'); + $accessor_meta->command(1); # don't let plugins pass arguments to reader methods $accessor_meta->pass_args(0); } for my $method (@{ $self->commands }) { my $method_meta = $self->find_method_by_name($method); - Moose::Util::apply_all_roles($method_meta->meta, 'Bot::Games::Meta::Role::Command'); + $method_meta->command(1); # don't let plugins pass arguments to generated methods (?) $accessor_meta->pass_args(0); } diff --git a/lib/Bot/Games/Meta/Role/Command.pm b/lib/Bot/Games/Meta/Role/Command.pm index adad41c..b0c5865 100644 --- a/lib/Bot/Games/Meta/Role/Command.pm +++ b/lib/Bot/Games/Meta/Role/Command.pm @@ -2,6 +2,12 @@ package Bot::Games::Meta::Role::Command; use Moose::Role; +has command => ( + is => 'rw', + isa => 'Bool', + default => 0, +); + has pass_args => ( is => 'rw', isa => 'Bool', diff --git a/lib/Bot/Games/OO.pm b/lib/Bot/Games/OO.pm index 48c51d7..abe8238 100644 --- a/lib/Bot/Games/OO.pm +++ b/lib/Bot/Games/OO.pm @@ -2,6 +2,7 @@ package Bot::Games::OO; use Moose (); use Moose::Exporter; +use Moose::Util::MetaRole; use Bot::Games::Meta::Class; @@ -13,7 +14,7 @@ sub command { package_name => $class, name => $name, ); - Moose::Util::apply_all_roles($method_meta->meta, 'Bot::Games::Meta::Role::Command'); + $method_meta->command(1); $class->meta->add_method($name, $method_meta); } @@ -24,7 +25,13 @@ Moose::Exporter->setup_import_methods( sub init_meta { shift; - return Moose->init_meta(@_, metaclass => 'Bot::Games::Meta::Class'); + my %options = @_; + Moose->init_meta(%options, metaclass => 'Bot::Games::Meta::Class'); + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $options{for_class}, + method_metaclass_roles => ['Bot::Games::Meta::Role::Command'], + ); + return $options{for_class}->meta; } 1; |