summaryrefslogtreecommitdiffstats
path: root/lib/App/Hiveminder/Command/Decline.pm
blob: da34aaca8f9ec22dbcac83d6f77b01ac4942b009 (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
#!/usr/bin/perl
package App::Hiveminder::Command::Decline;
use Moose;
use App::Hiveminder::Utils qw/parse_args display_tasks/;
extends 'App::Hiveminder::Command';

=head2 NAME

App::Hiveminder::Command::Decline - Decline offered tasks

=cut

sub command_names { qw/decline/ }

sub command {
    my $self = shift;

    return unless @_ > 0;
    my $ret = '';
    for my $task ($hm->get_tasks(%{ parse_args @_ })) {
        my $updated_task = $hm->update_task($task, accepted => 0);
        # we get a task hash with each field undef if it succeeds
        if (!defined $updated_task->{id}) {
            $ret .= "Declined " . display_tasks($task) . "\n";
        }
    }

    return $ret;
}

__PACKAGE__->meta()->make_immutable();
1;