ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.2
Committed: Sun Apr 27 17:27:34 2008 UTC (16 years, 2 months ago) by elmex
Content type: application/x-troff
Branch: MAIN
Changes since 1.1: +50 -20 lines
Log Message:
improved documentation of AnyEvent::Handle and the readline test to test the constructor passed callbacks.

File Contents

# Content
1 #!perl
2 use strict;
3 use AnyEvent::Handle;
4 use Test::More tests => 2;
5 use Socket;
6
7
8 {
9 my $cv = AnyEvent->condvar;
10
11 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
12
13 my $rd_ae = AnyEvent::Handle->new (fh => $rd);
14 my $concat;
15
16 $rd_ae->on_eof (sub { $cv->broadcast });
17 $rd_ae->readlines (sub {
18 my ($rd_ae, @lines) = @_;
19 for (@lines) {
20 chomp;
21 $concat .= $_;
22 }
23 });
24
25 $wr->syswrite ("A\nBC\nDEF\nG\n");
26 $wr->syswrite (("X" x 113) . "\n");
27 $wr->close;
28
29 $cv->wait;
30
31 is ($concat, "ABCDEFG".("X"x113), 'lines were read correctly');
32 }
33
34 {
35 my $cv = AnyEvent->condvar;
36
37 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
38
39 my $concat;
40
41 my $rd_ae =
42 AnyEvent::Handle->new (
43 fh => $rd,
44 on_eof => sub { $cv->broadcast },
45 on_readline => sub {
46 my ($rd_ae, @lines) = @_;
47 for (@lines) {
48 chomp;
49 $concat .= $_;
50 }
51 }
52 );
53
54 $wr->syswrite ("A\nBC\nDEF\nG\n");
55 $wr->syswrite (("X" x 113) . "\n");
56 $wr->close;
57
58 $cv->wait;
59
60 is ($concat, "ABCDEFG".("X"x113), 'second lines were read correctly');
61 }