line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hubot::Adapter::Shell; |
2
|
|
|
|
|
|
|
$Hubot::Adapter::Shell::VERSION = '0.2.7'; |
3
|
1
|
|
|
1
|
|
1856
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use namespace::autoclean; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Encode 'decode_utf8'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Hubot::Adapter'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use AnyEvent; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Hubot::Message; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'robot' => ( is => 'ro', isa => 'Hubot::Robot', ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_prompt' => ( is => 'rw', isa => 'Str', writer => 'setPrompt', ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'cv' => ( is => 'ro', lazy_build => 1, ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_cv { AnyEvent->condvar } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub close { shift->cv->send } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub send { |
25
|
|
|
|
|
|
|
my ( $self, $user, @strings ) = @_; |
26
|
|
|
|
|
|
|
print "$_\n" for @strings; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub reply { |
30
|
|
|
|
|
|
|
my ( $self, $user, @strings ) = @_; |
31
|
|
|
|
|
|
|
@strings = map { $user->{name} . ": $_" } @strings; |
32
|
|
|
|
|
|
|
$self->send( $user, @strings ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub exist { |
36
|
|
|
|
|
|
|
my ( $self, $user, $nick ) = @_; |
37
|
|
|
|
|
|
|
return $self->userForName($nick); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub run { |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
local $| = 1; |
44
|
|
|
|
|
|
|
binmode STDOUT, ':encoding(UTF-8)'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->emit('connected'); |
47
|
|
|
|
|
|
|
$self->setPrompt( $self->robot->name . "> " ); |
48
|
|
|
|
|
|
|
print $self->_prompt; |
49
|
|
|
|
|
|
|
my $w; |
50
|
|
|
|
|
|
|
$w = AnyEvent->io( |
51
|
|
|
|
|
|
|
fh => \*STDIN, |
52
|
|
|
|
|
|
|
poll => 'r', |
53
|
|
|
|
|
|
|
cb => sub { |
54
|
|
|
|
|
|
|
local $| = 1; |
55
|
|
|
|
|
|
|
chomp( my $input = decode_utf8(<STDIN>) ); |
56
|
|
|
|
|
|
|
if ( lc($input) eq 'exit' ) { |
57
|
|
|
|
|
|
|
$self->robot->shutdown; |
58
|
|
|
|
|
|
|
exit; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $user |
62
|
|
|
|
|
|
|
= $self->userForId( 1, { name => 'Shell', room => 'Shell', } ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->receive( |
65
|
|
|
|
|
|
|
new Hubot::TextMessage( { user => $user, text => $input, } ) ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
print $self->_prompt; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->cv->recv; |
72
|
|
|
|
|
|
|
exit; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding utf-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Hubot::Adapter::Shell - Shell adapter for L<Hubot> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 0.2.7 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$ hubot |
94
|
|
|
|
|
|
|
$ hubot -a shell # same |
95
|
|
|
|
|
|
|
hubot> exit |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DESCRIPTION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The shell adapter is an adapter that provides a simple REPL for interacting with a hubot locally. It is useful for testing scripts before deploying them. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<https://github.com/github/hubot/wiki/Adapter:-Shell> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Hyungsuk Hong <hshong@perl.kr> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Hyungsuk Hong. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
114
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |