diff options
author | doy <doy@tozt.net> | 2009-04-26 22:45:31 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-26 22:45:31 -0500 |
commit | 32fd1dc2b00e47196e1eba9c394c37a6957558ae (patch) | |
tree | 9dfe196e37b45e47670d87fdf032ce4bacdf0ff9 | |
parent | 689d4735313006f5d9a8e66e2f907a2187c0e0da (diff) | |
download | bot-games-32fd1dc2b00e47196e1eba9c394c37a6957558ae.tar.gz bot-games-32fd1dc2b00e47196e1eba9c394c37a6957558ae.zip |
fix up the formatter attribute metaclass to be more like the command attribute metaclass, so that it actually works, hopefully
-rw-r--r-- | lib/Bot/Games/Trait/Attribute/Formatted.pm | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/Bot/Games/Trait/Attribute/Formatted.pm b/lib/Bot/Games/Trait/Attribute/Formatted.pm index dd40a19..8eaa11c 100644 --- a/lib/Bot/Games/Trait/Attribute/Formatted.pm +++ b/lib/Bot/Games/Trait/Attribute/Formatted.pm @@ -10,13 +10,31 @@ has formatter => ( predicate => 'has_formatter', ); +before _process_options => sub { + my $self = shift; + my ($name, $options) = @_; + warn "only commands will have a formatter applied" + if exists($options->{formatter}) && !$options->{command}; +}; + +around accessor_metaclass => sub { + my $orig = shift; + my $self = shift; + my $metaclass = $self->$orig(@_); + return $metaclass unless $self->has_formatter; + return Moose::Meta::Class->create_anon_class( + superclasses => [$metaclass], + roles => ['Bot::Games::Trait::Method::Formatted'], + cache => 1, + )->name; +}; + after install_accessors => sub { my $self = shift; if ($self->has_formatter) { my $formatter = $self->formatter; my $method_meta = $self->get_read_method_ref; - $method_meta->formatter($formatter) - if $method_meta->can('formatter'); + $method_meta->formatter($formatter); } }; |