ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.2 by elmex, Sun Apr 27 17:27:34 2008 UTC vs.
Revision 1.5 by elmex, Mon Apr 28 08:01:05 2008 UTC

256=item B<readlines ($callback)> 256=item B<readlines ($callback)>
257 257
258=item B<readlines ($sep, $callback)> 258=item B<readlines ($sep, $callback)>
259 259
260This method will read lines from the filehandle, seperated by C<$sep> or C<"\n"> 260This method will read lines from the filehandle, seperated by C<$sep> or C<"\n">
261if C<$sep> is not provided. C<$sep> will be used as part of a regex, so it can be 261if C<$sep> is not provided. C<$sep> will be used as "line" seperator.
262a regex itself and won't be quoted!
263 262
264The C<$callback> will be called when at least one 263The C<$callback> will be called when at least one
265line could be read. The first argument to the C<$callback> will be the L<AnyEvent::Handle> 264line could be read. The first argument to the C<$callback> will be the L<AnyEvent::Handle>
266object itself and the rest of the arguments will be the read lines. 265object itself and the rest of the arguments will be the read lines.
267 266
268NOTE: This method will override any callbacks installed via the C<on_read> method. 267NOTE: This method will override any callbacks installed via the C<on_read> method.
269 268
270=cut 269=cut
271 270
272sub readlines { 271sub readlines {
273 my ($self, $NL, $cb) = @_; 272 my ($self, $sep, $cb) = @_;
274 273
275 if (ref $NL) { 274 if (ref $sep) {
276 $cb = $NL; 275 $cb = $sep;
277 $NL = "\n"; 276 $sep = "\n";
277
278 } elsif (not defined $sep) {
279 $sep = "\n";
278 } 280 }
281
282 my $sep_len = length $sep;
279 283
280 $self->{on_readline} = $cb; 284 $self->{on_readline} = $cb;
281 285
282 $self->on_read (sub { 286 $self->on_read (sub {
283 my @lines; 287 my @lines;
284 push @lines, $1 while $_[0]->{rbuf} =~ s/(.*)$NL//; 288 my $rb = \$_[0]->{rbuf};
289 my $pos;
290 while (($pos = index ($$rb, $sep)) >= 0) {
291 push @lines, substr $$rb, 0, $pos + $sep_len, '';
292 }
285 $self->{on_readline}->($_[0], @lines); 293 $self->{on_readline}->($_[0], @lines);
286 }); 294 });
287} 295}
288 296
289=item B<write ($data)> 297=item B<write ($data)>
359 367
360=head1 AUTHOR 368=head1 AUTHOR
361 369
362Robin Redeker, C<< <elmex at ta-sa.org> >> 370Robin Redeker, C<< <elmex at ta-sa.org> >>
363 371
364=head1 BUGS
365
366Please report any bugs or feature requests to
367C<bug-io-anyevent at rt.cpan.org>, or through the web interface at
368L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-AnyEvent>.
369I will be notified, and then you'll automatically be notified of progress on
370your bug as I make changes.
371
372=head1 SUPPORT
373
374You can find documentation for this module with the perldoc command.
375
376 perldoc AnyEvent::Handle
377
378You can also look for information at:
379
380=over 4
381
382=item * AnnoCPAN: Annotated CPAN documentation
383
384L<http://annocpan.org/dist/IO-AnyEvent>
385
386=item * CPAN Ratings
387
388L<http://cpanratings.perl.org/d/IO-AnyEvent>
389
390=item * RT: CPAN's request tracker
391
392L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-AnyEvent>
393
394=item * Search CPAN
395
396L<http://search.cpan.org/dist/IO-AnyEvent>
397
398=back
399
400=head1 ACKNOWLEDGEMENTS
401
402=head1 COPYRIGHT & LICENSE
403
404Copyright 2008 Robin Redeker, all rights reserved.
405
406This program is free software; you can redistribute it and/or modify it
407under the same terms as Perl itself.
408
409=cut 372=cut
410 373
4111; # End of AnyEvent::Handle 3741; # End of AnyEvent::Handle

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines