From 188ad8e49c1fa2802eaa55b3d4ae978f2c58c23c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 31 Oct 2009 15:16:49 -0500 Subject: convert Bot::Games to use IM::Engine::Plugin::Commands --- lib/Bot/Games/Trait/Attribute/Formatted.pm | 58 ------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 lib/Bot/Games/Trait/Attribute/Formatted.pm (limited to 'lib/Bot/Games/Trait/Attribute/Formatted.pm') diff --git a/lib/Bot/Games/Trait/Attribute/Formatted.pm b/lib/Bot/Games/Trait/Attribute/Formatted.pm deleted file mode 100644 index 00db707..0000000 --- a/lib/Bot/Games/Trait/Attribute/Formatted.pm +++ /dev/null @@ -1,58 +0,0 @@ -package Bot::Games::Trait::Attribute::Formatted; -use Bot::Games::OO::Role; - -# when the attribute is being constructed, the accessor methods haven't been -# generated yet, so we need to store the formatter here, and then apply it -# after the accessor methods exist -has formatter => ( - is => 'rw', - isa => 'CodeRef', - 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}; -}; - -after attach_to_class => sub { - my $self = shift; - my ($meta) = @_; - return if $self->has_formatter; - return unless $self->command; - return unless $self->has_type_constraint; - my $tc = $self->type_constraint; - for my $tc_name ($meta->formattable_tcs) { - if ($tc->is_a_type_of($tc_name)) { - $self->formatter($meta->formatter_for($tc_name)); - return; - } - } -}; - -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); - } -}; - -no Bot::Games::OO::Role; - -1; -- cgit v1.2.3-54-g00ecf