line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hubot::TextListener; |
2
|
|
|
|
|
|
|
$Hubot::TextListener::VERSION = '0.2.7'; |
3
|
1
|
|
|
1
|
|
1890
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use namespace::autoclean; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Hubot::Listener'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'regex' => ( is => 'ro', isa => 'RegexpRef', ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub BUILD { |
11
|
|
|
|
|
|
|
my $self = shift; |
12
|
|
|
|
|
|
|
$self->matcher( |
13
|
|
|
|
|
|
|
sub { |
14
|
|
|
|
|
|
|
my $message = shift; |
15
|
|
|
|
|
|
|
if ( 'Hubot::TextMessage' eq ( ref $message ) ) { |
16
|
|
|
|
|
|
|
my $regex = $self->regex; |
17
|
|
|
|
|
|
|
return $message->text =~ m/$regex/; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
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.7 |
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 |