summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Meta/Role/Attribute/Command.pm
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-04-26 19:21:10 -0500
committerdoy <doy@tozt.net>2009-04-26 19:21:10 -0500
commit27da6e113d34fef72de8b95b7261c137d6f9ef76 (patch)
tree465ec1a6b5dad9b6d5cb9fb964b85631917c6a99 /lib/Bot/Games/Meta/Role/Attribute/Command.pm
parent39d4781a8db91a1892ffb170117a7e623348ebc3 (diff)
downloadbot-games-27da6e113d34fef72de8b95b7261c137d6f9ef76.tar.gz
bot-games-27da6e113d34fef72de8b95b7261c137d6f9ef76.zip
renamespace a bunch of things
Diffstat (limited to 'lib/Bot/Games/Meta/Role/Attribute/Command.pm')
-rw-r--r--lib/Bot/Games/Meta/Role/Attribute/Command.pm45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Bot/Games/Meta/Role/Attribute/Command.pm b/lib/Bot/Games/Meta/Role/Attribute/Command.pm
new file mode 100644
index 0000000..bf3ea50
--- /dev/null
+++ b/lib/Bot/Games/Meta/Role/Attribute/Command.pm
@@ -0,0 +1,45 @@
+package Bot::Games::Meta::Role::Attribute::Command;
+use Moose::Role;
+
+has command => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 0,
+);
+
+has needs_init => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 1,
+);
+
+before _process_options => sub {
+ my $self = shift;
+ my ($name, $options) = @_;
+ warn "needs_init is useless for attributes without command"
+ if exists($options->{needs_init}) && !$options->{command};
+};
+
+around accessor_metaclass => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $metaclass = $self->$orig(@_);
+ return $metaclass unless $self->command;
+ return Moose::Meta::Class->create_anon_class(
+ superclasses => [$metaclass],
+ roles => ['Bot::Games::Meta::Role::Method::Command'],
+ cache => 1,
+ )->name;
+};
+
+after install_accessors => sub {
+ my $self = shift;
+ return unless $self->command;
+ my $method_meta = $self->get_read_method_ref;
+ $method_meta->pass_args(0);
+ $method_meta->needs_init($self->needs_init);
+};
+
+no Moose::Role;
+
+1;