source: client/trunk/lib/Sophie/Client/Term.pm @ 152

Last change on this file since 152 was 152, checked in by nanardon, 13 years ago
  • manage end-user config
File size: 2.0 KB
Line 
1package Sophie::Client::Term;
2
3use 5.012002;
4use strict;
5use warnings;
6use Term::ReadLine;
7use base qw(Sophie::Client);
8
9our $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
18sub show_reply {
19    my ($self, $heap, $reply) = @_;
20    print "$_\n" foreach (@{$reply->{message}});
21}
22
23sub user_config {
24    my ($self, $heap, $var, $value) = @_;
25
26    $self->set_var('client', { $var => $value });
27}
28
29sub 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
461;
47
48__END__
49# Below is stub documentation for your module. You'd better edit it!
50
51=head1 NAME
52
53Sophie::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
62Stub documentation for Sophie::Client, created by h2xs. It looks like the
63author of the extension was negligent enough to leave the stub
64unedited.
65
66Blah blah blah.
67
68
69=head1 SEE ALSO
70
71Mention other useful documentation such as the documentation of
72related modules or operating system documentation (such as man pages
73in UNIX), or any relevant external documentation such as RFCs or
74standards.
75
76If you have a mailing list set up for your module, mention it here.
77
78If you have a web site set up for your module, mention it here.
79
80=head1 AUTHOR
81
82Olivier Thauvin, E<lt>olivier@localdomainE<gt>
83
84=head1 COPYRIGHT AND LICENSE
85
86Copyright (C) 2010 by Olivier Thauvin
87
88This library is free software; you can redistribute it and/or modify
89it under the same terms as Perl itself, either Perl version 5.12.2 or,
90at your option, any later version of Perl 5 you may have available.
91
92
93=cut
Note: See TracBrowser for help on using the repository browser.