1Tie::Simple(3) User Contributed Perl Documentation Tie::Simple(3)
2
3
4
6 Tie::Simple - Variable ties made easier: much, much, much easier...
7
9 version 1.04
10
12 use Tie::Simple;
13
14 tie $scalar, 'Tie::Simple', $data,
15 FETCH => sub { ... },
16 STORE => sub { ... };
17
18 tie @array, 'Tie::Simple', $data,
19 FETCH => sub { ... },
20 STORE => sub { ... },
21 FETCHSIZE => sub { ... },
22 STORESIZE => sub { ... },
23 EXTEND => sub { ... },
24 EXISTS => sub { ... },
25 DELETE => sub { ... },
26 CLEAR => sub { ... },
27 PUSH => sub { ... },
28 POP => sub { ... },
29 SHIFT => sub { ... },
30 UNSHIFT => sub { ... },
31 SPLICE => sub { ... };
32
33 tie %hash, 'Tie::Simple', $data,
34 FETCH => sub { ... },
35 STORE => sub { ... },
36 DELETE => sub { ... },
37 CLEAR => sub { ... },
38 EXISTS => sub { ... },
39 FIRSTKEY => sub { ... },
40 NEXTKEY => sub { ... };
41
42 tie *HANDLE, 'Tie::Simple', $data,
43 WRITE => sub { ... },
44 PRINT => sub { ... },
45 PRINTF => sub { ... },
46 READ => sub { ... },
47 READLINE => sub { ... },
48 GETC => sub { ... },
49 CLOSE => sub { ... };
50
52 This module adds the ability to quickly create new types of tie objects
53 without creating a complete class. It does so in such a way as to try
54 and make the programmers life easier when it comes to single-use ties
55 that I find myself wanting to use from time-to-time.
56
57 The "Tie::Simple" package is actually a front-end to other classes
58 which really do all the work once tied, but this package does the
59 dwimming to automatically figure out what you're trying to do.
60
61 I've tried to make this as intuitive as possible and dependent on other
62 bits of Perl where I can to minimize the need for documentation and to
63 make this extra, extra spiffy.
64
66 To setup your quick tie, simply start with the typical tie statement on
67 the variable you're tying. You should always tie to the "Tie::Simple"
68 package and not directly to the other packages included with this
69 module as those are only present as helpers (even though they are
70 really the tie classes).
71
72 The type of tie depends upon the type of the first argument given to
73 tie. This should be rather obvious from the "SYNOPSIS" above.
74 Therefore, the arguments are:
75
76 1. The variable to be tied.
77
78 2. The string 'Tie::Simple'.
79
80 3. A scalar value (hereafter called the "local data").
81
82 4. A list of name/CODE pairs.
83
84 At this point, you'll need to have some understanding of tying before
85 you can continue. I suggest looking through perltie.
86
87 As you will note in the perltie documentation, every tie package
88 defines functions whose first argument is called "this". The third
89 argument, local data, will take the place of "this" in all the
90 subroutine calls you define in the name/CODE pair list. Each name
91 should be the name of the function that would be defined for the
92 appropriate tie-type if you were to do a full-blown package definition.
93 The subroutine matched to that name will take the exact arguments
94 specified in the perltie documentation, but instead of "this" it will
95 be given the local data scalar value you set (which could even be
96 "undef" if you don't need it).
97
99 The synopsis above shows the typical subroutines you could define. (I
100 left out the "UNTIE" and "DESTROY" methods, but you may define these if
101 you need them, but be sure to read the perltie documentation on
102 possible caveats.) However, the "SYNOPSIS" is way more complete then
103 you probably need to be in most cases. This is because "Tie::Simple"
104 does it's best to make use of some of the handy Perl built-ins which
105 help with creating tie packages.
106
107 SCALARS
108 If you are creating a scalar tie, then you can assume all the benefits
109 of being a Tie::Scalar.
110
111 ARRAYS
112 If you are creating an array tie, then you may assume all the benefits
113 of being a Tie::Array.
114
115 HASHES
116 If you are creating a hash tie, then you may assume all the benefits of
117 being a Tie::Hash.
118
119 HANDLES
120 If you are creating a handle tie, then you may assume all the benefits
121 of being a Tie::Handle.
122
124 It sure would be nice if you could declare custom @ISA lists, wouldn't
125 it? I'd like to add such a feature, but coming up with some custom
126 "SUPER::" dispatch code or generating new "anonymous" packages are the
127 only ways I can think to do it. I don't really have time to add such a
128 feature just now.
129
131 perltie, Tie::Scalar, Tie::Array, Tie::Hash, Tie::Handle
132
134 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
135
137 This software is copyright (c) 2015 by Qubling Software LLC.
138
139 This is free software; you can redistribute it and/or modify it under
140 the same terms as the Perl 5 programming language system itself.
141
142
143
144perl v5.32.0 2020-07-28 Tie::Simple(3)