5 Tie::Handle - base class definitions for tied handles
14 sub READ { ... } # Provide a needed method
15 sub TIEHANDLE { ... } # Overrides inherited method
24 This module provides some skeletal methods for handle-tying classes. See
25 L<perltie> for a list of the functions required in tying a handle to a package.
26 The basic B<Tie::Handle> package provides a C<new> method, as well as methods
27 C<TIESCALAR>, C<FETCH> and C<STORE>. The C<new> method is provided as a means
28 of grandfathering, for classes that forget to provide their own C<TIESCALAR>
31 For developers wishing to write their own tied-handle classes, the methods
32 are summarized below. The L<perltie> section not only documents these, but
33 has sample code as well:
37 =item TIEHANDLE classname, LIST
39 The method invoked by the command C<tie *glob, classname>. Associates a new
40 glob instance with the specified class. C<LIST> would represent additional
41 arguments (along the lines of L<AnyDBM_File> and compatriots) needed to
42 complete the association.
44 =item WRITE this, scalar, length, offset
46 Write I<length> bytes of data from I<scalar> starting at I<offset>.
48 =item PRINT this, LIST
50 Print the values in I<LIST>
52 =item PRINTF this, format, LIST
54 Print the values in I<LIST> using I<format>
56 =item READ this, scalar, length, offset
58 Read I<length> bytes of data into I<scalar> starting at I<offset>.
66 Get a single character
74 Free the storage associated with the tied handle referenced by I<this>.
75 This is rarely needed, as Perl manages its memory quite well. But the
76 option exists, should a class wish to perform specific actions upon the
77 destruction of an instance.
81 =head1 MORE INFORMATION
83 The L<perltie> section contains an example of tying handles.
94 # "Grandfather" the new, a la Tie::Hash
98 if (defined &{"{$pkg}::new"}) {
99 carp "WARNING: calling ${pkg}->new since ${pkg}->TIEHANDLE is missing"
104 croak "$pkg doesn't define a TIEHANDLE method";
110 if($self->can('WRITE') != \&WRITE) {
111 my $buf = join(defined $, ? $, : "",@_);
112 $buf .= $\ if defined $\;
113 $self->WRITE($buf,length($buf),0);
116 croak ref($self)," doesn't define a PRINT method";
123 if($self->can('WRITE') != \&WRITE) {
124 my $buf = sprintf(@_);
125 $self->WRITE($buf,length($buf),0);
128 croak ref($self)," doesn't define a PRINTF method";
134 croak "$pkg doesn't define a READLINE method";
140 if($self->can('READ') != \&READ) {
146 croak ref($self)," doesn't define a GETC method";
152 croak "$pkg doesn't define a READ method";
157 croak "$pkg doesn't define a WRITE method";
162 croak "$pkg doesn't define a CLOSE method";