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