summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-24 00:05:28 -0500
committerdoy <doy@tozt.net>2009-01-24 00:05:28 -0500
commitab75274e0677c58460c2ba1f73fbf05d04cb59c0 (patch)
treecf9d7be61b64deadb10c3125b29795f122675a68
parentcd5e21bb6036d410017c3b863c5ffb4d9270bcb6 (diff)
downloadbot-games-ab75274e0677c58460c2ba1f73fbf05d04cb59c0.tar.gz
bot-games-ab75274e0677c58460c2ba1f73fbf05d04cb59c0.zip
stop using fixed method metaclasses, just generate anonymous ones when needed - this allows for replacing the metaclass of an already created method
-rw-r--r--lib/Bot/Games/Meta/Method/Accessor/Command.pm10
-rw-r--r--lib/Bot/Games/Meta/Method/Command.pm10
-rw-r--r--lib/Bot/Games/Meta/Role/Attribute.pm11
-rw-r--r--lib/Bot/Games/OO.pm18
4 files changed, 21 insertions, 28 deletions
diff --git a/lib/Bot/Games/Meta/Method/Accessor/Command.pm b/lib/Bot/Games/Meta/Method/Accessor/Command.pm
deleted file mode 100644
index 1d0d025..0000000
--- a/lib/Bot/Games/Meta/Method/Accessor/Command.pm
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/perl
-package Bot::Games::Meta::Method::Accessor::Command;
-use Moose;
-extends 'Moose::Meta::Method::Accessor';
-with 'Bot::Games::Meta::Role::Command';
-
-__PACKAGE__->meta->make_immutable(inline_constructor => 0);
-no Moose;
-
-1;
diff --git a/lib/Bot/Games/Meta/Method/Command.pm b/lib/Bot/Games/Meta/Method/Command.pm
deleted file mode 100644
index 2728292..0000000
--- a/lib/Bot/Games/Meta/Method/Command.pm
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/perl
-package Bot::Games::Meta::Method::Command;
-use Moose;
-extends 'Moose::Meta::Method';
-with 'Bot::Games::Meta::Role::Command';
-
-__PACKAGE__->meta->make_immutable;
-no Moose;
-
-1;
diff --git a/lib/Bot/Games/Meta/Role/Attribute.pm b/lib/Bot/Games/Meta/Role/Attribute.pm
index 6ed8f01..70d36e6 100644
--- a/lib/Bot/Games/Meta/Role/Attribute.pm
+++ b/lib/Bot/Games/Meta/Role/Attribute.pm
@@ -2,8 +2,6 @@
package Bot::Games::Meta::Role::Attribute;
use Moose::Role;
-use Bot::Games::Meta::Method::Accessor::Command;
-
has command => (
is => 'rw',
isa => 'Bool',
@@ -13,8 +11,13 @@ has command => (
around accessor_metaclass => sub {
my $orig = shift;
my $self = shift;
- return $self->command ? 'Bot::Games::Meta::Method::Accessor::Command'
- : $self->$orig(@_);
+ my $metaclass = $self->$orig(@_);
+ return $metaclass unless $self->command;
+ return Moose::Meta::Class->create_anon_class(
+ superclasses => [$metaclass],
+ roles => ['Bot::Games::Meta::Role::Command'],
+ cache => 1,
+ )->name;
};
after install_accessors => sub {
diff --git a/lib/Bot/Games/OO.pm b/lib/Bot/Games/OO.pm
index 9a9075f..708f146 100644
--- a/lib/Bot/Games/OO.pm
+++ b/lib/Bot/Games/OO.pm
@@ -4,13 +4,23 @@ use Moose ();
use Moose::Exporter;
use Moose::Util::MetaRole;
-use Bot::Games::Meta::Method::Command;
-
sub command {
my $class = shift;
my ($name, $code) = @_;
- return unless $code; # XXX: fix this later
- my $method_meta = Bot::Games::Meta::Method::Command->wrap(
+ my $superclass = 'Moose::Meta::Method';
+ if (!$code) {
+ my $method_meta = $class->meta->remove_method($name);
+ die "Can't set $name as a command, it doesn't exist"
+ unless blessed $method_meta;
+ $superclass = blessed $method_meta;
+ $code = $method_meta->body;
+ }
+ my $method_metaclass = Moose::Meta::Class->create_anon_class(
+ superclasses => [$superclass],
+ roles => ['Bot::Games::Meta::Role::Command'],
+ cache => 1,
+ )->name;
+ my $method_meta = $method_metaclass->wrap(
$code,
package_name => $class,
name => $name,