| 1 | package Hubot::TextListener; | ||||||||||
| 2 | 6 | $Hubot::TextListener::VERSION = '0.2.8'; | |||||||||
| 3 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | extends 'Hubot::Listener'; | |||||||||
| 7 | |||||||||||
| 8 | 6 | has 'regex' => ( is => 'ro', isa => 'RegexpRef', ); | |||||||||
| 9 | |||||||||||
| 10 | 19 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | 19 | my $self = shift; | |||||||||
| 12 | $self->matcher( | ||||||||||
| 13 | 168 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 14 | 168 | my $message = shift; | |||||||||
| 15 | 168 | ▶ | if ( 'Hubot::TextMessage' eq ( ref $message ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 84 | my $regex = $self->regex; | |||||||||
| 17 | 84 | return $message->text =~ m/$regex/; | |||||||||
| 18 | } | ||||||||||
| 19 | 84 | return; | |||||||||
| 20 | } | ||||||||||
| 21 | 19 | ); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||
| 25 | |||||||||||
| 26 | 6 | 1; | |||||||||
| 27 | |||||||||||
| 28 | =pod | ||||||||||
| 29 | |||||||||||
| 30 | =encoding utf-8 | ||||||||||
| 31 | |||||||||||
| 32 | =head1 NAME | ||||||||||
| 33 | |||||||||||
| 34 | Hubot::TextListener - text Listener for hubot | ||||||||||
| 35 | |||||||||||
| 36 | =head1 VERSION | ||||||||||
| 37 | |||||||||||
| 38 | version 0.2.8 | ||||||||||
| 39 | |||||||||||
| 40 | =head1 SYNOPSIS | ||||||||||
| 41 | |||||||||||
| 42 | use Hubot::TextListener; | ||||||||||
| 43 | Hubot::TextListener->new( | ||||||||||
| 44 | robot => $robot, # $robot is Hubot::Robot | ||||||||||
| 45 | regex => qr/hi/, | ||||||||||
| 46 | callback => sub { | ||||||||||
| 47 | my $msg = shift; # $msg is Hubot::Response | ||||||||||
| 48 | $msg->reply('hi'); | ||||||||||
| 49 | } | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||
| 53 | |||||||||||
| 54 | try to match L<Hubot::TextMessage> then execute callback with matching result and input messages. | ||||||||||
| 55 | |||||||||||
| 56 | =head1 SEE ALSO | ||||||||||
| 57 | |||||||||||
| 58 | <Hubot::TextMessage> | ||||||||||
| 59 | |||||||||||
| 60 | =head1 AUTHOR | ||||||||||
| 61 | |||||||||||
| 62 | Hyungsuk Hong <hshong@perl.kr> | ||||||||||
| 63 | |||||||||||
| 64 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 65 | |||||||||||
| 66 | This software is copyright (c) 2012 by Hyungsuk Hong. | ||||||||||
| 67 | |||||||||||
| 68 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 69 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||