sub CLOSE {
my $pkg = ref $_[0];
croak "$pkg doesn't define a CLOSE method";
-}
+}
package Tie::StdHandle;
-our @ISA = 'Tie::Handle';
+our @ISA = 'Tie::Handle';
use Carp;
sub TIEHANDLE
bless $fh,$class;
$fh->OPEN(@_) if (@_);
return $fh;
-}
+}
sub EOF { eof($_[0]) }
sub TELL { tell($_[0]) }
sub BINMODE { binmode($_[0]) }
sub OPEN
-{
+{
$_[0]->CLOSE if defined($_[0]->FILENO);
- open($_[0],$_[1]);
+ @_ == 2 ? open($_[0], $_[1]) : open($_[0], $_[1], $_[2]);
}
sub READ { read($_[0],$_[1],$_[2]) }
sub GETC { getc($_[0]) }
sub WRITE
-{
+{
my $fh = $_[0];
print $fh substr($_[1],0,$_[2])
}
$f = 'tst';
-print "1..13\n";
+print "1..13\n";
# my $file tests
-unlink("afile.new") if -f "afile";
-print "$!\nnot " unless open($f,"+>afile");
+unlink("afile.new") if -f "afile";
+print "$!\nnot " unless open($f,"+>afile") && open($f, "+<", "afile");
print "ok 1\n";
print "$!\nnot " unless binmode($f);
print "ok 2\n";
-print "not " unless -f "afile";
+print "not " unless -f "afile";
print "ok 3\n";
print "not " unless print $f "SomeData\n";
print "ok 4\n";
print "ok 12\n";
print "not " unless close($f);
print "ok 13\n";
-unlink("afile");
+unlink("afile");