1Tie::Handle(3pm) Perl Programmers Reference Guide Tie::Handle(3pm)
2
3
4
6 Tie::Handle - base class definitions for tied handles
7
9 package NewHandle;
10 require Tie::Handle;
11
12 @ISA = qw(Tie::Handle);
13
14 sub READ { ... } # Provide a needed method
15 sub TIEHANDLE { ... } # Overrides inherited method
16
17
18 package main;
19
20 tie *FH, 'NewHandle';
21
23 This module provides some skeletal methods for handle-tying classes.
24 See perltie for a list of the functions required in tying a handle to a
25 package. The basic Tie::Handle package provides a "new" method, as
26 well as methods "TIEHANDLE", "PRINT", "PRINTF" and "GETC".
27
28 For developers wishing to write their own tied-handle classes, the
29 methods are summarized below. The perltie section not only documents
30 these, but has sample code as well:
31
32 TIEHANDLE classname, LIST
33 The method invoked by the command "tie *glob, classname".
34 Associates a new glob instance with the specified class. "LIST"
35 would represent additional arguments (along the lines of
36 AnyDBM_File and compatriots) needed to complete the association.
37
38 WRITE this, scalar, length, offset
39 Write length bytes of data from scalar starting at offset.
40
41 PRINT this, LIST
42 Print the values in LIST
43
44 PRINTF this, format, LIST
45 Print the values in LIST using format
46
47 READ this, scalar, length, offset
48 Read length bytes of data into scalar starting at offset.
49
50 READLINE this
51 Read a single line
52
53 GETC this
54 Get a single character
55
56 CLOSE this
57 Close the handle
58
59 OPEN this, filename
60 (Re-)open the handle
61
62 BINMODE this
63 Specify content is binary
64
65 EOF this
66 Test for end of file.
67
68 TELL this
69 Return position in the file.
70
71 SEEK this, offset, whence
72 Position the file.
73
74 Test for end of file.
75
76 DESTROY this
77 Free the storage associated with the tied handle referenced by
78 this. This is rarely needed, as Perl manages its memory quite
79 well. But the option exists, should a class wish to perform
80 specific actions upon the destruction of an instance.
81
83 The perltie section contains an example of tying handles.
84
86 This version of Tie::Handle is neither related to nor compatible with
87 the Tie::Handle (3.0) module available on CPAN. It was due to an
88 accident that two modules with the same name appeared. The namespace
89 clash has been cleared in favor of this module that comes with the perl
90 core in September 2000 and accordingly the version number has been
91 bumped up to 4.0.
92
93
94
95perl v5.36.0 2022-08-30 Tie::Handle(3pm)