Skip Menu |

This queue is for tickets about the IO-String CPAN distribution.

Report information
The Basics
Id: 50513
Status: new
Priority: 0/
Queue: IO-String

People
Owner: Nobody in particular
Requestors: NUFFIN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] support $/ = \$length in getline
Subject: 0001-support-length-in-getline.patch
From d2a54ca6d9a85651707a5354c1b8e7d4f7cdb876 Mon Sep 17 00:00:00 2001 From: Yuval Kogman <nothingmuch@woobling.org> Date: Thu, 15 Oct 2009 05:58:30 +0200 Subject: [PATCH] support $/ = \$length in getline uses $io->read($buf, ${ $/ }); --- String.pm | 5 +++++ t/read.t | 26 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletions(-) diff --git a/String.pm b/String.pm index 4bc8e71..76b9877 100644 --- a/String.pm +++ b/String.pm @@ -225,6 +225,11 @@ sub getline return substr($$buf, $pos); } + if ( ref $/ ) { + return undef unless $self->read(my $buf, ${ $/ }); + return $buf; + } + unless (length $/) { # paragraph mode # XXX slow&lazy implementation using getc() my $para = ""; diff --git a/t/read.t b/t/read.t index 3c87668..c234980 100644 --- a/t/read.t +++ b/t/read.t @@ -1,4 +1,4 @@ -print "1..17\n"; +print "1..20\n"; $str = <<EOT; This is an example @@ -107,3 +107,27 @@ print "ok 16\n"; $str = ""; print "not " if defined(read($io, $buf, 4)); print "ok 17\n"; + + +$str = "blah\nblah\n"; + +$io->setpos(0); + +{ + local $/ = \7; + + my $line = $io->getline; + + print "not " unless defined($line) and $line eq "blah\nbl"; + print "ok 18\n"; + + $line = $io->getline; + + print "not " unless defined($line) and $line eq "ah\n"; + print "ok 19\n"; + + $line = $io->getline; + + print "not " if defined($line); + print "ok 20\n"; +} -- 1.6.4.3