| 1 | package Hubot::Adapter::Shell; | ||||||||||
| 2 | 1 | $Hubot::Adapter::Shell::VERSION = '0.2.8'; | |||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Encode 'decode_utf8'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | extends 'Hubot::Adapter'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use AnyEvent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Hubot::Message; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | has 'robot' => ( is => 'ro', isa => 'Hubot::Robot', ); | |||||||||
| 15 | |||||||||||
| 16 | 1 | has '_prompt' => ( is => 'rw', isa => 'Str', writer => 'setPrompt', ); | |||||||||
| 17 | |||||||||||
| 18 | 1 | has 'cv' => ( is => 'ro', lazy_build => 1, ); | |||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub _build_cv { AnyEvent->condvar } | ||||||||
|
Subroutine
_build_cv: not called CC=1 SCAR=6.9
| |||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub close { shift->cv->send } | ||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub send { | ||||||||
|
Subroutine
send: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 25 | 0 | my ( $self, $user, @strings ) = @_; | |||||||||
| 26 | 0 | print "$_\n" for @strings; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub reply { | ||||||||
|
Subroutine
reply: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 0 | my ( $self, $user, @strings ) = @_; | |||||||||
| 31 | 0 | @strings = map { $user->{name} . ": $_" } @strings; | |||||||||
| 32 | 0 | $self->send( $user, @strings ); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub exist { | ||||||||
|
Subroutine
exist: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | 0 | my ( $self, $user, $nick ) = @_; | |||||||||
| 37 | 0 | return $self->userForName($nick); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 41 | 0 | my $self = shift; | |||||||||
| 42 | |||||||||||
| 43 | 0 | local $| = 1; | |||||||||
| 44 | 0 | binmode STDOUT, ':encoding(UTF-8)'; | |||||||||
| 45 | |||||||||||
| 46 | 0 | $self->emit('connected'); | |||||||||
| 47 | 0 | $self->setPrompt( $self->robot->name . "> " ); | |||||||||
| 48 | 0 | print $self->_prompt; | |||||||||
| 49 | 0 | my $w; | |||||||||
| 50 | $w = AnyEvent->io( | ||||||||||
| 51 | fh => \*STDIN, | ||||||||||
| 52 | poll => 'r', | ||||||||||
| 53 | 0 | ▶ | cb => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 54 | 0 | local $| = 1; | |||||||||
| 55 | 0 | chomp( my $input = decode_utf8(<STDIN>) ); | |||||||||
| 56 | 0 | ▶ | if ( lc($input) eq 'exit' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | $self->robot->shutdown; | |||||||||
| 58 | 0 | exit; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | my $user | |||||||||
| 62 | = $self->userForId( 1, { name => 'Shell', room => 'Shell', } ); | ||||||||||
| 63 | |||||||||||
| 64 | 0 | $self->receive( | |||||||||
| 65 | new Hubot::TextMessage( { user => $user, text => $input, } ) ); | ||||||||||
| 66 | |||||||||||
| 67 | 0 | print $self->_prompt; | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | ); | |||||||||
| 70 | |||||||||||
| 71 | 0 | $self->cv->recv; | |||||||||
| 72 | 0 | exit; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 76 | |||||||||||
| 77 | 1 | 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.8 | ||||||||||
| 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 | ||||||||||