package Tie::Handle;
+use 5.006_001;
+our $VERSION = '4.1';
+
=head1 NAME
Tie::Handle, Tie::StdHandle - base class definitions for tied handles
package NewHandle;
require Tie::Handle;
-
- @ISA = (Tie::Handle);
-
+
+ @ISA = qw(Tie::Handle);
+
sub READ { ... } # Provide a needed method
sub TIEHANDLE { ... } # Overrides inherited method
-
-
+
+
package main;
-
+
tie *FH, 'NewHandle';
=head1 DESCRIPTION
are summarized below. The L<perltie> section not only documents these, but
has sample code as well:
-=over
+=over 4
=item TIEHANDLE classname, LIST
The L<perltie> section contains an example of tying handles.
+=head1 COMPATIBILITY
+
+This version of Tie::Handle is neither related to nor compatible with
+the Tie::Handle (3.0) module available on CPAN. It was due to an
+accident that two modules with the same name appeared. The namespace
+clash has been cleared in favor of this module that comes with the
+perl core in September 2000 and accordingly the version number has
+been bumped up to 4.0.
+
=cut
use Carp;
+use warnings::register;
sub new {
my $pkg = shift;
sub TIEHANDLE {
my $pkg = shift;
if (defined &{"{$pkg}::new"}) {
- carp "WARNING: calling ${pkg}->new since ${pkg}->TIEHANDLE is missing"
- if $^W;
+ warnings::warnif("WARNING: calling ${pkg}->new since ${pkg}->TIEHANDLE is missing");
$pkg->new(@_);
}
else {
sub CLOSE {
my $pkg = ref $_[0];
croak "$pkg doesn't define a CLOSE method";
-}
+}
package Tie::StdHandle;
-use vars qw(@ISA);
-@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])
}