summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Trait/Class/Formatted.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-06-01 01:55:08 -0500
committerJesse Luehrs <doy@tozt.net>2009-06-01 01:55:08 -0500
commitb25a41e690cfeea828e4a06d3c7cefabc3113898 (patch)
treec794c7e247aaa9d7609df339ad0d6b48bd0bdbf2 /lib/Bot/Games/Trait/Class/Formatted.pm
parentb74e5167fea789d09b7fe05c2f93b8ef07fe2eb9 (diff)
downloadbot-games-b25a41e690cfeea828e4a06d3c7cefabc3113898.tar.gz
bot-games-b25a41e690cfeea828e4a06d3c7cefabc3113898.zip
make the default formatters an attribute of the metaclass
Diffstat (limited to 'lib/Bot/Games/Trait/Class/Formatted.pm')
-rw-r--r--lib/Bot/Games/Trait/Class/Formatted.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Bot/Games/Trait/Class/Formatted.pm b/lib/Bot/Games/Trait/Class/Formatted.pm
new file mode 100644
index 0000000..403bba6
--- /dev/null
+++ b/lib/Bot/Games/Trait/Class/Formatted.pm
@@ -0,0 +1,27 @@
+package Bot::Games::Trait::Class::Formatted;
+use Moose::Role;
+use MooseX::AttributeHelpers;
+
+has default_formatters => (
+ metaclass => 'Collection::ImmutableHash',
+ is => 'ro',
+ isa => 'HashRef[CodeRef]',
+ builder => '_build_default_formatters',
+ provides => {
+ get => 'formatter_for',
+ exists => 'has_formatter',
+ keys => 'formattable_tcs',
+ },
+);
+
+sub _build_default_formatters {
+ {
+ 'ArrayRef' => sub { join ', ', @{ shift() } },
+ 'Bool' => sub { return shift() ? 'true' : 'false' },
+ 'Object' => sub { shift() . "" },
+ }
+}
+
+no Moose::Role;
+
+1;