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

=head2 NAME

App::Hiveminder::Command::Delete - Delete a task by locator

=cut

sub command_names { qw/delete rm del/ }

sub command {
    my ($self, $args) = @_;
    # XXX: offer an interactive mode here, possibly
    my $ret = '';
    for my $locator (@$args) {
        my $desc = display_tasks($self->hm->read_task($locator));
        $ret .= "Deleted $desc\n";
        eval { $self->hm->delete('Task', id => $self->hm->loc2id($locator)) };
        warn $@ unless $@ =~ /404 Not Found/;
    }
    chomp $ret;
    return $ret;
}

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