summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Trait/Class/Formatted.pm
diff options
context:
space:
mode:
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;