| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::TeleGramma::BotAction::Listen; | 
| 2 |  |  |  |  |  |  | $App::TeleGramma::BotAction::Listen::VERSION = '0.13'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Base class for bot actions that listen | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 4 |  |  | 4 |  | 23 | use Mojo::Base 'App::TeleGramma::BotAction'; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 6 | 4 |  |  | 4 |  | 447 | use App::TeleGramma::Constants qw/:const/; | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 1244 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | has 'command'; | 
| 9 |  |  |  |  |  |  | has 'response'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 0 |  |  | 0 | 0 | 0 | sub can_listen { 1 } | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub process_message { | 
| 14 | 7 |  |  | 7 | 0 | 68 | my $self = shift; | 
| 15 | 7 |  |  |  |  | 11 | my $msg  = shift; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 7 |  |  |  |  | 23 | my $cmd = $self->command; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 7 | 50 | 33 |  |  | 35 | if ($msg->text && ! ref($cmd) && $msg->text =~ /^\Q$cmd\E \b @?/x) { | 
|  |  |  | 33 |  |  |  |  | 
| 20 | 0 |  |  |  |  | 0 | my ($body) = ($msg->text =~ /^ \S+ \s+ (.*)$/x); | 
| 21 | 0 | 0 |  |  |  | 0 | return $self->response->($msg, $body) if defined $body; # return body of command, if it existed | 
| 22 | 0 |  |  |  |  | 0 | return $self->response->($msg); | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 7 | 100 | 33 |  |  | 71 | if ($msg->text && ref($cmd) eq 'Regexp' && $msg->text =~ $cmd) { | 
|  |  |  | 66 |  |  |  |  | 
| 26 | 5 |  |  |  |  | 89 | my $body = ($msg->text); | 
| 27 | 5 | 50 |  |  |  | 31 | return $self->response->($msg, $body) if defined $body; # return body of command, if it existed | 
| 28 | 0 |  |  |  |  | 0 | return $self->response->($msg); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 2 |  |  |  |  | 33 | return PLUGIN_DECLINED; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | 1; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | __END__ | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =pod | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =encoding UTF-8 | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 NAME | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | App::TeleGramma::BotAction::Listen - Base class for bot actions that listen | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head1 VERSION | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | version 0.13 | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =head1 AUTHOR | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Justin Hawkins <justin@eatmorecode.com> | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | This software is copyright (c) 2017 by Justin Hawkins <justin@eatmorecode.com>. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 59 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =cut |