diff options
Diffstat (limited to 'lib/IM/Engine/Plugin/Commands/Trait/Class/Formatted.pm')
-rw-r--r-- | lib/IM/Engine/Plugin/Commands/Trait/Class/Formatted.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/IM/Engine/Plugin/Commands/Trait/Class/Formatted.pm b/lib/IM/Engine/Plugin/Commands/Trait/Class/Formatted.pm new file mode 100644 index 0000000..71c9249 --- /dev/null +++ b/lib/IM/Engine/Plugin/Commands/Trait/Class/Formatted.pm @@ -0,0 +1,26 @@ +package IM::Engine::Plugin::Commands::Trait::Class::Formatted; +use Moose::Role; + +has default_formatters => ( + traits => ['Hash'], + is => 'ro', + isa => 'HashRef[CodeRef]', + builder => '_build_default_formatters', + handles => { + formatter_for => 'get', + has_formatter => 'exists', + formattable_tcs => 'keys', + }, +); + +sub _build_default_formatters { + { + 'ArrayRef' => sub { join ', ', @{ shift() } }, + 'Bool' => sub { return shift() ? 'true' : 'false' }, + 'Object' => sub { shift() . "" }, + } +} + +no Moose::Role; + +1; |