This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta updated for new version of Module::CoreList
[perl5.git] / lib / Tie / StdHandle.pm
CommitLineData
6269bcb3
MS
1package Tie::StdHandle;
2
d10ced8a
NC
3use strict;
4
6269bcb3 5use Tie::Handle;
d10ced8a
NC
6use vars qw(@ISA $VERSION);
7@ISA = 'Tie::Handle';
8$VERSION = '4.2';
9
10=head1 NAME
11
12Tie::StdHandle - base class definitions for tied handles
13
14=head1 SYNOPSIS
15
16 package NewHandle;
17 require Tie::Handle;
18
19 @ISA = qw(Tie::Handle);
20
21 sub READ { ... } # Provide a needed method
22 sub TIEHANDLE { ... } # Overrides inherited method
23
24
25 package main;
26
27 tie *FH, 'NewHandle';
28
29=head1 DESCRIPTION
30
31The B<Tie::StdHandle> package provide most methods for file handles described
32in L<perltie> (the exceptions are C<UNTIE> and C<DESTROY>). It causes tied
33file handles to behave exactly like standard file handles and allow for
34selective overwriting of methods.
35
36=cut
6269bcb3
MS
37
38sub TIEHANDLE
39{
40 my $class = shift;
41 my $fh = \do { local *HANDLE};
42 bless $fh,$class;
43 $fh->OPEN(@_) if (@_);
44 return $fh;
45}
46
47sub EOF { eof($_[0]) }
48sub TELL { tell($_[0]) }
49sub FILENO { fileno($_[0]) }
50sub SEEK { seek($_[0],$_[1],$_[2]) }
51sub CLOSE { close($_[0]) }
52sub BINMODE { binmode($_[0]) }
53
54sub OPEN
55{
56 $_[0]->CLOSE if defined($_[0]->FILENO);
57 @_ == 2 ? open($_[0], $_[1]) : open($_[0], $_[1], $_[2]);
58}
59
60sub READ { read($_[0],$_[1],$_[2]) }
61sub READLINE { my $fh = $_[0]; <$fh> }
62sub GETC { getc($_[0]) }
63
64sub WRITE
65{
66 my $fh = $_[0];
67 print $fh substr($_[1],0,$_[2])
68}
69
70
711;