From da928b59285b96179db5cecd1325efe3aff1e93b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 1 Jun 2009 02:51:02 -0500 Subject: allow specifying a type constraint name instead of a coderef as a formatter --- lib/Bot/Games/OO/Game.pm | 7 ++++++- lib/Bot/Games/Trait/Method/Formatted.pm | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/Bot') diff --git a/lib/Bot/Games/OO/Game.pm b/lib/Bot/Games/OO/Game.pm index 0bc294a..2da71bd 100644 --- a/lib/Bot/Games/OO/Game.pm +++ b/lib/Bot/Games/OO/Game.pm @@ -30,7 +30,12 @@ sub command { $class->meta->add_method($name, $method_meta); } for my $attr (map { $_->meta->get_attribute_list } @method_metaclass_roles) { - $method_meta->$attr($args{$attr}) if exists $args{$attr}; + next unless exists $args{$attr}; + my $value = $args{$attr}; + my $munge_method = "_munge_$attr"; + $value = $method_meta->$munge_method($value) + if $method_meta->can($munge_method); + $method_meta->$attr($value); } } diff --git a/lib/Bot/Games/Trait/Method/Formatted.pm b/lib/Bot/Games/Trait/Method/Formatted.pm index 0145bea..7e0b986 100644 --- a/lib/Bot/Games/Trait/Method/Formatted.pm +++ b/lib/Bot/Games/Trait/Method/Formatted.pm @@ -10,6 +10,13 @@ has formatter => ( } }, ); +sub _munge_formatter { + my $self = shift; + my ($format) = @_; + return $format if ref($format) eq 'CODE'; + return $self->associated_metaclass->formatter_for($format); +} + no Moose::Role; 1; -- cgit v1.2.3-54-g00ecf