« lib/Monitoring/Spooler/Cmd/Command/list.pm
↑ Summary
lib/Monitoring/Spooler/Transport/Smstrade.pm »
| 1 | package Monitoring::Spooler::Cmd::Command::rm; | ||
| 2 | $Monitoring::Spooler::Cmd::Command::rm::VERSION = '0.05'; | ||
| 3 | BEGIN { | ||
| 4 | $Monitoring::Spooler::Cmd::Command::rm::AUTHORITY = 'cpan:TEX'; | ||
| 5 | } | ||
| 6 | # ABSTRACT: remove a single message | ||
| 7 | |||
| 8 | use 5.010_000; | ||
| 9 | use mro 'c3'; | ||
| 10 | use feature ':5.10'; | ||
| 11 | |||
| 12 | use Moose; | ||
| 13 | use namespace::autoclean; | ||
| 14 | |||
| 15 | # use IO::Handle; | ||
| 16 | # use autodie; | ||
| 17 | # use MooseX::Params::Validate; | ||
| 18 | # use Carp; | ||
| 19 | # use English qw( -no_match_vars ); | ||
| 20 | # use Try::Tiny; | ||
| 21 | |||
| 22 | # extends ... | ||
| 23 | extends 'Monitoring::Spooler::Cmd::Command'; | ||
| 24 | # has ... | ||
| 25 | has 'message_id' => ( | ||
| 26 | 'is' => 'ro', | ||
| 27 | 'isa' => 'Int', | ||
| 28 | 'required' => 1, | ||
| 29 | 'traits' => [qw(Getopt)], | ||
| 30 | 'cmd_aliases' => 'm', | ||
| 31 | 'documentation' => 'Remove the message identified by this ID', | ||
| 32 | ); | ||
| 33 | # with ... | ||
| 34 | # initializers ... | ||
| 35 | |||
| 36 | # your code here ... | ||
| 37 | sub execute { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | # remove a single message from the queue | ||
| 41 | my $sql = 'DELETE FROM msg_queue WHERE id = ?'; | ||
| 42 | my $sth = $self->dbh()->prepare($sql); | ||
| 43 | if(!$sth) { | ||
| 44 | $self->logger()->log( message => 'Could not prepare statement: '.$self->dbh()->errstr, level => 'warning', ); | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | if($sth->execute($self->message_id())) { | ||
| 48 | $self->logger()->log( message => 'Deleted message #'.$self->message_id().' from queue.', level => 'debug', ); | ||
| 49 | $sth->finish(); | ||
| 50 | return 1; | ||
| 51 | } else { | ||
| 52 | $self->logger()->log( message => 'Could not execute statement: '.$sth->errstr, level => 'warning', ); | ||
| 53 | $sth->finish(); | ||
| 54 | return; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | sub abstract { | ||
| 59 | return "Remove a single message from the notification queue."; | ||
| 60 | } | ||
| 61 | |||
| 62 | no Moose; | ||
| 63 | __PACKAGE__->meta->make_immutable; | ||
| 64 | |||
| 65 | 1; | ||
| 66 | |||
| 67 | __END__ |