1 | package Sophie::Client::Term; |
---|
2 | |
---|
3 | use 5.012002; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | use Term::ReadLine; |
---|
7 | use base qw(Sophie::Client); |
---|
8 | |
---|
9 | our $VERSION = '0.01'; |
---|
10 | |
---|
11 | { |
---|
12 | open (my $fh, "/dev/tty" ) |
---|
13 | or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }'; |
---|
14 | die $@ if $@; |
---|
15 | close ($fh); |
---|
16 | } |
---|
17 | |
---|
18 | sub show_reply { |
---|
19 | my ($self, $heap, $reply) = @_; |
---|
20 | print "$_\n" foreach (@{$reply->{message}}); |
---|
21 | } |
---|
22 | |
---|
23 | sub user_config { |
---|
24 | my ($self, $heap, $var, $value) = @_; |
---|
25 | |
---|
26 | $self->set_var('client', { $var => $value }); |
---|
27 | } |
---|
28 | |
---|
29 | sub run { |
---|
30 | my ($self) = @_; |
---|
31 | |
---|
32 | my $term = Term::ReadLine->new('Sophie'); |
---|
33 | $term->MinLine(99999); |
---|
34 | my $OUT = $term->OUT || \*STDOUT; |
---|
35 | |
---|
36 | while (1) { |
---|
37 | defined (my $line = $term->readline('Sophie > ')) or do { |
---|
38 | print $OUT "\n"; |
---|
39 | return; |
---|
40 | }; |
---|
41 | $self->handle_message(undef, [ 'client' ], $line); |
---|
42 | $term->addhistory($line); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | 1; |
---|
47 | |
---|
48 | __END__ |
---|
49 | # Below is stub documentation for your module. You'd better edit it! |
---|
50 | |
---|
51 | =head1 NAME |
---|
52 | |
---|
53 | Sophie::Client - Perl extension for blah blah blah |
---|
54 | |
---|
55 | =head1 SYNOPSIS |
---|
56 | |
---|
57 | use Sophie::Client; |
---|
58 | blah blah blah |
---|
59 | |
---|
60 | =head1 DESCRIPTION |
---|
61 | |
---|
62 | Stub documentation for Sophie::Client, created by h2xs. It looks like the |
---|
63 | author of the extension was negligent enough to leave the stub |
---|
64 | unedited. |
---|
65 | |
---|
66 | Blah blah blah. |
---|
67 | |
---|
68 | |
---|
69 | =head1 SEE ALSO |
---|
70 | |
---|
71 | Mention other useful documentation such as the documentation of |
---|
72 | related modules or operating system documentation (such as man pages |
---|
73 | in UNIX), or any relevant external documentation such as RFCs or |
---|
74 | standards. |
---|
75 | |
---|
76 | If you have a mailing list set up for your module, mention it here. |
---|
77 | |
---|
78 | If you have a web site set up for your module, mention it here. |
---|
79 | |
---|
80 | =head1 AUTHOR |
---|
81 | |
---|
82 | Olivier Thauvin, E<lt>olivier@localdomainE<gt> |
---|
83 | |
---|
84 | =head1 COPYRIGHT AND LICENSE |
---|
85 | |
---|
86 | Copyright (C) 2010 by Olivier Thauvin |
---|
87 | |
---|
88 | This library is free software; you can redistribute it and/or modify |
---|
89 | it under the same terms as Perl itself, either Perl version 5.12.2 or, |
---|
90 | at your option, any later version of Perl 5 you may have available. |
---|
91 | |
---|
92 | |
---|
93 | =cut |
---|