This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Text::ParseWords 3.27
[perl5.git] / lib / Tie / StdHandle.pm
CommitLineData
6269bcb3
MS
1package Tie::StdHandle;
2
3use Tie::Handle;
4our @ISA = 'Tie::Handle';
5use Carp;
6
7sub TIEHANDLE
8{
9 my $class = shift;
10 my $fh = \do { local *HANDLE};
11 bless $fh,$class;
12 $fh->OPEN(@_) if (@_);
13 return $fh;
14}
15
16sub EOF { eof($_[0]) }
17sub TELL { tell($_[0]) }
18sub FILENO { fileno($_[0]) }
19sub SEEK { seek($_[0],$_[1],$_[2]) }
20sub CLOSE { close($_[0]) }
21sub BINMODE { binmode($_[0]) }
22
23sub OPEN
24{
25 $_[0]->CLOSE if defined($_[0]->FILENO);
26 @_ == 2 ? open($_[0], $_[1]) : open($_[0], $_[1], $_[2]);
27}
28
29sub READ { read($_[0],$_[1],$_[2]) }
30sub READLINE { my $fh = $_[0]; <$fh> }
31sub GETC { getc($_[0]) }
32
33sub WRITE
34{
35 my $fh = $_[0];
36 print $fh substr($_[1],0,$_[2])
37}
38
39
401;