Debian Codegraph @

eg/event

raw
1 #!/usr/bin/perl
2
3 # this crap is an asynchronous finger client. it's rather idiotic ;)
4
5 use Coro;
6 use Coro::Socket;
7 use Coro::Event;
8 use AnyEvent;
9
10 my $quit = AnyEvent->condvar;
11
12 # this gets started everytime a user enters a finger command
13 sub finger {
14 my $user = shift;
15 my $host = shift;
16
17 my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger"
18 or die "$user\@$host: $!";
19
20 print $fh "$user\n";
21
22 print "$user\@$host: $_" while <$fh>;
23 print "$user\@$host: done\n";
24 }
25
26 # display the time or garble the display, YMMV.
27 async {
28 my $w = Coro::Event->timer (interval => 0.001, hard => 1);
29 use Time::HiRes qw(time);
30 while () {
31 $w->next;
32 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ", time, "> \e8";
33 };
34 };
35
36 my $stdin = new_from_fh Coro::Handle \*STDIN;
37
38 $SIG{PIPE} = 'IGNORE';
39
40 $| = 1;
41 while() {
42 print "cmd (finger|quit)> "; my $cmd = <$stdin>; chomp $cmd;
43 if ($cmd eq "finger") {
44 print "user> "; my $user = <$stdin>; chomp $user;
45 print "host> "; my $host = <$stdin>; chomp $host;
46 async { finger $user, $host };
47 } elsif ($cmd eq "quit") {
48 last;
49 } else {
50 print "unknown command '$cmd', either 'finger' or 'quit'\n";
51 }
52 }
53