line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hubot::Scripts::eval; |
2
|
|
|
|
|
|
|
$Hubot::Scripts::eval::VERSION = '0.1.9'; |
3
|
1
|
|
|
1
|
|
2481
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use JSON::XS; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2778
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub load { |
8
|
0
|
|
|
0
|
0
|
|
my ( $class, $robot ) = @_; |
9
|
|
|
|
|
|
|
$robot->hear( |
10
|
|
|
|
|
|
|
qr/^eval:? on *$/i, |
11
|
|
|
|
|
|
|
sub { |
12
|
0
|
|
|
0
|
|
|
my $msg = shift; |
13
|
0
|
|
|
|
|
|
$robot->brain->{data}{eval}{ $msg->message->user->{name} } |
14
|
|
|
|
|
|
|
{recording} = 1; |
15
|
0
|
|
|
|
|
|
$msg->send( 'OK, recording ' |
16
|
|
|
|
|
|
|
. $msg->message->user->{name} |
17
|
|
|
|
|
|
|
. "'s codes for evaluate" ); |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$robot->hear( |
22
|
|
|
|
|
|
|
qr/^eval:? (?:off|finish|done) *$/i, |
23
|
|
|
|
|
|
|
sub { |
24
|
0
|
|
|
0
|
|
|
my $msg = shift; |
25
|
0
|
|
0
|
|
|
|
my $code = join "\n", |
26
|
0
|
|
|
|
|
|
@{ $robot->brain->{data}{eval}{ $msg->message->user->{name} } |
27
|
|
|
|
|
|
|
{code} ||= [] }; |
28
|
|
|
|
|
|
|
$msg->http('http://api.dan.co.jp/lleval.cgi') |
29
|
|
|
|
|
|
|
->query( { s => "#!/usr/bin/perl\n$code" } )->get( |
30
|
|
|
|
|
|
|
sub { |
31
|
0
|
|
|
|
|
|
my ( $body, $hdr ) = @_; |
32
|
0
|
0
|
0
|
|
|
|
return if ( !$body || $hdr->{Status} !~ m/^2/ ); |
33
|
0
|
|
|
|
|
|
my $data = decode_json($body); |
34
|
0
|
|
0
|
|
|
|
$msg->send( split /\n/, |
35
|
|
|
|
|
|
|
$data->{stdout} || $data->{stderr} ); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
); |
38
|
0
|
|
|
|
|
|
delete $robot->brain->{data}{eval}{ $msg->message->user->{name} }; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$robot->hear( |
43
|
|
|
|
|
|
|
qr/^eval:? cancel *$/i, |
44
|
|
|
|
|
|
|
sub { |
45
|
0
|
|
|
0
|
|
|
my $msg = shift; |
46
|
0
|
|
|
|
|
|
delete $robot->brain->{data}{eval}{ $msg->message->user->{name} }; |
47
|
0
|
|
|
|
|
|
$msg->send( 'canceled ' |
48
|
|
|
|
|
|
|
. $msg->message->user->{name} |
49
|
|
|
|
|
|
|
. "'s evaluation recording" ); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$robot->hear( |
54
|
|
|
|
|
|
|
qr/^eval:? (.+)/i, |
55
|
|
|
|
|
|
|
sub { |
56
|
0
|
|
|
0
|
|
|
my $msg = shift; |
57
|
0
|
|
|
|
|
|
my $code = $msg->match->[0]; |
58
|
0
|
0
|
|
|
|
|
if ( $code !~ m/^(?:on|off|finish|done|cancel)$/ ) { |
59
|
|
|
|
|
|
|
$msg->http('http://api.dan.co.jp/lleval.cgi') |
60
|
|
|
|
|
|
|
->query( { s => "#!/usr/bin/perl\n$code" } )->get( |
61
|
|
|
|
|
|
|
sub { |
62
|
0
|
|
|
|
|
|
my ( $body, $hdr ) = @_; |
63
|
0
|
0
|
0
|
|
|
|
return if ( !$body || $hdr->{Status} !~ m/^2/ ); |
64
|
0
|
|
|
|
|
|
my $data = decode_json($body); |
65
|
0
|
|
0
|
|
|
|
$msg->send( split /\n/, |
66
|
|
|
|
|
|
|
$data->{stdout} || $data->{stderr} ); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$robot->catchAll( |
74
|
|
|
|
|
|
|
sub { |
75
|
0
|
|
|
0
|
|
|
my $msg = shift; |
76
|
0
|
0
|
|
|
|
|
if ( $robot->brain->{data}{eval}{ $msg->message->user->{name} } |
77
|
|
|
|
|
|
|
{recording} ) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
0
|
|
|
|
|
if ( ref $msg->message eq 'Hubot::TextMessage' ) { |
80
|
0
|
0
|
0
|
|
|
|
push @{ $robot->brain->{data}{eval} |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
{ $msg->message->user->{name} }{code} ||= [] }, |
82
|
|
|
|
|
|
|
$msg->message->text |
83
|
|
|
|
|
|
|
if $msg->message->text !~ /^eval:? on *$/; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Hubot::Scripts::eval |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 VERSION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
version 0.1.9 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SYNOPSIS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
eval <code> - evaluate <code> and show the result |
103
|
|
|
|
|
|
|
eval on - start recording |
104
|
|
|
|
|
|
|
eval off|finish|done - evaluate recorded <code> and show the result |
105
|
|
|
|
|
|
|
eval cancel - cancel recording |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Hyungsuk Hong <hshong@perl.kr> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |