summaryrefslogtreecommitdiffstats
path: root/lib/IM/Engine/Plugin/Commands/Command.pm
blob: 5b6b46d2376c931da2286fe8e043f221cf31a2d5 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package IM::Engine::Plugin::Commands::Command;
use IM::Engine::Plugin::Commands::OO;

has help => (
    is         => 'ro',
    isa        => 'Str',
    default    => 'This command has no help text!',
    command    => 1,
    needs_init => 0,
);

has is_active => (
    is         => 'rw',
    isa        => 'Bool',
    command    => 1,
    needs_init => 0,
);

has _ime_plugin => (
    is       => 'ro',
    isa      => 'IM::Engine::Plugin',
    required => 1,
    weak_ref => 1,
);

sub default {
    confess "Commands must implement a default method";
}

command cmdlist => sub {
    my $self = shift;
    my @commands;
    for my $method ($self->meta->get_all_methods) {
        push @commands, $method->name
            if $method->meta->can('does_role')
            && $method->meta->does_role('IM::Engine::Plugin::Commands::Trait::Method::Command');
    }
    return \@commands;
}, needs_init => 0,
   formatter => sub {
       my $list = shift;
       return join ' ', sort map { '-' . $_ } @$list
   };

sub say {
    my $self = shift;
    $self->_ime_plugin->say(@_);
}

__PACKAGE__->meta->make_immutable;
no IM::Engine::Plugin::Commands::OO;

1;