line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Simple; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
101385
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
136
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
154
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
2061
|
use Tie::Simple::Scalar; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
112
|
|
9
|
4
|
|
|
4
|
|
2164
|
use Tie::Simple::Array; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
102
|
|
10
|
4
|
|
|
4
|
|
2152
|
use Tie::Simple::Hash; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
118
|
|
11
|
4
|
|
|
4
|
|
2015
|
use Tie::Simple::Handle; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
1042
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Tie::Simple - Variable ties made easier: much, much, much easier... |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Tie::Simple; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
tie $scalar, 'Tie::Simple', $data, |
22
|
|
|
|
|
|
|
FETCH => sub { ... }, |
23
|
|
|
|
|
|
|
STORE => sub { ... }; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
tie @array, 'Tie::Simple', $data, |
26
|
|
|
|
|
|
|
FETCH => sub { ... }, |
27
|
|
|
|
|
|
|
STORE => sub { ... }, |
28
|
|
|
|
|
|
|
FETCHSIZE => sub { ... }, |
29
|
|
|
|
|
|
|
STORESIZE => sub { ... }, |
30
|
|
|
|
|
|
|
EXTEND => sub { ... }, |
31
|
|
|
|
|
|
|
EXISTS => sub { ... }, |
32
|
|
|
|
|
|
|
DELETE => sub { ... }, |
33
|
|
|
|
|
|
|
CLEAR => sub { ... }, |
34
|
|
|
|
|
|
|
PUSH => sub { ... }, |
35
|
|
|
|
|
|
|
POP => sub { ... }, |
36
|
|
|
|
|
|
|
SHIFT => sub { ... }, |
37
|
|
|
|
|
|
|
UNSHIFT => sub { ... }, |
38
|
|
|
|
|
|
|
SPLICE => sub { ... }; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
tie %hash, 'Tie::Simple', $data, |
41
|
|
|
|
|
|
|
FETCH => sub { ... }, |
42
|
|
|
|
|
|
|
STORE => sub { ... }, |
43
|
|
|
|
|
|
|
DELETE => sub { ... }, |
44
|
|
|
|
|
|
|
CLEAR => sub { ... }, |
45
|
|
|
|
|
|
|
EXISTS => sub { ... }, |
46
|
|
|
|
|
|
|
FIRSTKEY => sub { ... }, |
47
|
|
|
|
|
|
|
NEXTKEY => sub { ... }; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
tie *HANDLE, 'Tie::Simple', $data, |
50
|
|
|
|
|
|
|
WRITE => sub { ... }, |
51
|
|
|
|
|
|
|
PRINT => sub { ... }, |
52
|
|
|
|
|
|
|
PRINTF => sub { ... }, |
53
|
|
|
|
|
|
|
READ => sub { ... }, |
54
|
|
|
|
|
|
|
READLINE => sub { ... }, |
55
|
|
|
|
|
|
|
GETC => sub { ... }, |
56
|
|
|
|
|
|
|
CLOSE => sub { ... }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This module adds the ability to quickly create new types of tie objects without |
61
|
|
|
|
|
|
|
creating a complete class. It does so in such a way as to try and make the |
62
|
|
|
|
|
|
|
programmers life easier when it comes to single-use ties that I find myself |
63
|
|
|
|
|
|
|
wanting to use from time-to-time. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The C package is actually a front-end to other classes which |
66
|
|
|
|
|
|
|
really do all the work once tied, but this package does the dwimming to |
67
|
|
|
|
|
|
|
automatically figure out what you're trying to do. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
I've tried to make this as intuitive as possible and dependent on other bits of |
70
|
|
|
|
|
|
|
Perl where I can to minimize the need for documentation and to make this extra, |
71
|
|
|
|
|
|
|
extra spiffy. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SIMPLE TYING |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
To setup your quick tie, simply start with the typical tie statement on the |
76
|
|
|
|
|
|
|
variable you're tying. You should always tie to the C package and |
77
|
|
|
|
|
|
|
not directly to the other packages included with this module as those are only |
78
|
|
|
|
|
|
|
present as helpers (even though they are really the tie classes). |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The type of tie depends upon the type of the first argument given to tie. This |
81
|
|
|
|
|
|
|
should be rather obvious from the L above. Therefore, the arguments |
82
|
|
|
|
|
|
|
are: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item 1. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The variable to be tied. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item 2. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The string C<'Tie::Simple'>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item 3. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
A scalar value (hereafter called the "local data"). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item 4. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
A list of name/CODE pairs. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
At this point, you'll need to have some understanding of tying before you can |
105
|
|
|
|
|
|
|
continue. I suggest looking through L. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
As you will note in the L documentation, every tie package defines |
108
|
|
|
|
|
|
|
functions whose first argument is called C. The third argument, |
109
|
|
|
|
|
|
|
local data, will take the place of C in all the subroutine calls you |
110
|
|
|
|
|
|
|
define in the name/CODE pair list. Each name should be the name of the function |
111
|
|
|
|
|
|
|
that would be defined for the appropriate tie-type if you were to do a |
112
|
|
|
|
|
|
|
full-blown package definition. The subroutine matched to that name will take |
113
|
|
|
|
|
|
|
the exact arguments specified in the L documentation, but instead of |
114
|
|
|
|
|
|
|
C it will be given the local data scalar value you set (which could even |
115
|
|
|
|
|
|
|
be C if you don't need it). |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 TIES CAN BE SIMPLER STILL |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The synopsis above shows the typical subroutines you could define. (I left out |
120
|
|
|
|
|
|
|
the C and C methods, but you may define these if you need them, |
121
|
|
|
|
|
|
|
but be sure to read the L documentation on possible caveats.) However, |
122
|
|
|
|
|
|
|
the L is way more complete then you probably need to be in most |
123
|
|
|
|
|
|
|
cases. This is because C does it's best to make use of some of |
124
|
|
|
|
|
|
|
the handy Perl built-ins which help with creating tie packages. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 SCALARS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
If you are creating a scalar tie, then you can assume all the benefits of being |
129
|
|
|
|
|
|
|
a L. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 ARRAYS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
If you are creating an array tie, then you may assume all the benefits of being |
134
|
|
|
|
|
|
|
a L. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 HASHES |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
If you are creating a hash tie, then you may assume all the benefits of being a |
139
|
|
|
|
|
|
|
L. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 HANDLES |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
If you are creating a handle tie, then you may assume all the benefits of being |
144
|
|
|
|
|
|
|
a L. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub TIESCALAR { |
149
|
1
|
|
|
1
|
|
22
|
my ($class, $data, %subs) = @_; |
150
|
1
|
50
|
|
|
|
5
|
die "Eat dirt and die! Use Tie::Simple and read the docs, you turkey!" |
151
|
|
|
|
|
|
|
unless $class eq 'Tie::Simple'; |
152
|
1
|
|
|
|
|
8
|
bless { data => $data, subs => \%subs }, 'Tie::Simple::Scalar'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub TIEARRAY { |
156
|
1
|
|
|
1
|
|
54
|
my ($class, $data, %subs) = @_; |
157
|
1
|
50
|
|
|
|
4
|
die "Eat dirt and die! Use Tie::Simple and read the docs, you turkey!" |
158
|
|
|
|
|
|
|
unless $class eq 'Tie::Simple'; |
159
|
1
|
|
|
|
|
7
|
bless { data => $data, subs => \%subs }, 'Tie::Simple::Array'; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub TIEHASH { |
163
|
1
|
|
|
1
|
|
35
|
my ($class, $data, %subs) = @_; |
164
|
1
|
50
|
|
|
|
4
|
die "Eat dirt and die! Use Tie::Simple and read the docs, you turkey!" |
165
|
|
|
|
|
|
|
unless $class eq 'Tie::Simple'; |
166
|
1
|
|
|
|
|
7
|
bless { data => $data, subs => \%subs }, 'Tie::Simple::Hash'; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub TIEHANDLE { |
170
|
2
|
|
|
2
|
|
1414
|
my ($class, $data, %subs) = @_; |
171
|
2
|
50
|
|
|
|
7
|
die "Eat dirt and die! Use Tie::Simple and read the docs, you turkey!" |
172
|
|
|
|
|
|
|
unless $class eq 'Tie::Simple'; |
173
|
2
|
|
|
|
|
12
|
bless { data => $data, subs => \%subs }, 'Tie::Simple::Handle'; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 TO DO |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
It sure would be nice if you could declare custom C<@ISA> lists, wouldn't it? |
179
|
|
|
|
|
|
|
I'd like to add such a feature, but coming up with some custom C |
180
|
|
|
|
|
|
|
dispatch code or generating new "anonymous" packages are the only ways I can |
181
|
|
|
|
|
|
|
think to do it. I don't really have time to add such a feature just now. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L, L, L, L, L |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 AUTHOR |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp, Ehanenkamp@users.sourceforge.netE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright 2004 Andrew Sterling Hanenkamp. All Rights Reserved. This library is |
194
|
|
|
|
|
|
|
made available under the same terms as Perl itself. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1 |