Tie::StdHandle::WRITE: handle offset
authorDavid Mitchell <davem@iabyn.com>
Wed, 23 Oct 2013 18:14:36 +0000 (19:14 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 23 Oct 2013 18:14:36 +0000 (19:14 +0100)
the WRITE method was ignoring its offset argument.

lib/Tie/Handle/stdhandle.t
lib/Tie/StdHandle.pm

index d00ab84..228004f 100644 (file)
@@ -5,7 +5,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-use Test::More tests => 25;
+use Test::More tests => 27;
 
 use_ok('Tie::StdHandle');
 
@@ -33,6 +33,8 @@ ok(print($f "ABCDEF\n"), "print ABCDEF");        # line 3
     ok(print($f "rhubarb"), "print rhubarb");    # line 4
 }
 
+ok(syswrite($f, "123456789\n", 3, 7), "syswrite");# line 5
+
 # read some lines back
 
 ok(seek($f,0,0), "seek");
@@ -65,6 +67,11 @@ ok(!eof($f), "eof");
 $b = <$f>;
 is($b, "rhubarbX\n", "b eq rhubarbX");
 
+# line 5
+
+$b = <$f>;
+is($b, "89\n", "b eq 89");
+
 ok(eof($f), "eof");
 ok(close($f), "close");
 
index f7750fd..159d72e 100644 (file)
@@ -65,7 +65,7 @@ sub WRITE
 {
  my $fh = $_[0];
  local $\; # don't print any line terminator
- print $fh substr($_[1],0,$_[2])
+ print $fh substr($_[1], $_[3], $_[2]);
 }