summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games/Trait/Method/Formatted.pm
blob: f5e6415795e3116169bad16d8fb918fe0b9593d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Bot::Games::Trait::Method::Formatted;
use Moose::Role;

has formatter => (
    is      => 'rw',
    isa     => 'CodeRef',
    default => sub { sub {
        my $self = shift;
        my ($to_print) = @_;
        if (blessed $to_print) {
            $to_print = "$to_print";
        }
        elsif (ref($to_print) && ref($to_print) eq 'ARRAY') {
            $to_print = join ', ', @$to_print;
        }
        elsif (!$to_print) {
            $to_print = 'false';
        }
        return $to_print;
    } },
);

no Moose::Role;

1;