line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl -w |
2
|
|
|
|
|
|
|
# -*- coding: utf-8-unix; tab-width: 4; -*- |
3
|
|
|
|
|
|
|
package Symbol::Values; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Symbol::Values.pm |
6
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
7
|
|
|
|
|
|
|
# Revision: $Id: Values.pm,v 1.29 2005/08/27 17:24:03 kay Exp $ |
8
|
|
|
|
|
|
|
# Written by Keitaro Miyazaki |
9
|
|
|
|
|
|
|
# Copyright 2005 Keitaro Miyazaki All Rights Reserved. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# HISTORY |
12
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
13
|
|
|
|
|
|
|
# 2005-08-28 Version 1.07 |
14
|
|
|
|
|
|
|
# - Make $@ untouched. |
15
|
|
|
|
|
|
|
# 2005-08-10 Version 1.06 |
16
|
|
|
|
|
|
|
# - Modefied test which failed on some platforms. |
17
|
|
|
|
|
|
|
# 2005-08-07 Version 1.05 |
18
|
|
|
|
|
|
|
# - Modefied test which failed on some platforms. |
19
|
|
|
|
|
|
|
# 2005-08-05 Version 1.04 |
20
|
|
|
|
|
|
|
# - Improved handling of name of special variables (e.g. "$:"). |
21
|
|
|
|
|
|
|
# - Changed error/warning messages. |
22
|
|
|
|
|
|
|
# - More comments. |
23
|
|
|
|
|
|
|
# - Create new hash/array value if they were not in the glob |
24
|
|
|
|
|
|
|
# when the user accessed to them through hash/array method. |
25
|
|
|
|
|
|
|
# 2005-08-04 Version 1.03 |
26
|
|
|
|
|
|
|
# - Fixed the bug could not access to special variables. |
27
|
|
|
|
|
|
|
# 2005-08-03 Version 1.0.2 |
28
|
|
|
|
|
|
|
# - Changed "use 5.008" to "use 5.006". |
29
|
|
|
|
|
|
|
# 2005-08-02 Version 1.01 |
30
|
|
|
|
|
|
|
# - Fixed typo regarding to package name in POD document. |
31
|
|
|
|
|
|
|
# - Improved warning message handling by "use warnings::register". |
32
|
|
|
|
|
|
|
# - The "new" method will raise exception when invalid symbol name |
33
|
|
|
|
|
|
|
# was passed. |
34
|
|
|
|
|
|
|
# 2005-07-31 Version 1.00 |
35
|
|
|
|
|
|
|
# - Initial version. |
36
|
|
|
|
|
|
|
# - Rewrited as CPAN module. |
37
|
|
|
|
|
|
|
# 2005-07-29 Wrote prototype of this module. |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
67492
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
40
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
41
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
30
|
|
42
|
1
|
|
|
1
|
|
6
|
use warnings::register; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
388
|
|
43
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
44
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
62
|
|
45
|
1
|
|
|
1
|
|
4
|
use Symbol (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
352
|
|
48
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
49
|
|
|
|
|
|
|
symbol |
50
|
|
|
|
|
|
|
) ] ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
our $VERSION = '1.07'; |
56
|
|
|
|
|
|
|
our $REVISION = '$Id: Values.pm,v 1.29 2005/08/27 17:24:03 kay Exp $'; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Symbol::Values - Provides consistent accessing interface to values of symbol. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Symbol::Values 'symbol'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub my_code { print "in original 'my_code'.\n" } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Get code object in symbol "my_code". |
69
|
|
|
|
|
|
|
my $orig_code = symbol("my_code")->code; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $wrapper = sub { |
72
|
|
|
|
|
|
|
print "before original 'my_code'.\n"; |
73
|
|
|
|
|
|
|
$orig_code->(); |
74
|
|
|
|
|
|
|
print "after original 'my_code'.\n"; |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Set code object in symbol "my_code". |
78
|
|
|
|
|
|
|
symbol("my_code")->code = $wrapper; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my_code(); # => before original 'my_code'. |
81
|
|
|
|
|
|
|
# in original 'my_code'. |
82
|
|
|
|
|
|
|
# after original 'my_code'. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 OBJECTIVE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
I've been feeling that glob notation of perl is little bit funny. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
One problem is that it lacks consistency in the way of |
91
|
|
|
|
|
|
|
fetching/storing values of a symbol. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
See examples below. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$code_ref = *name{CODE}; # Getting code object. |
96
|
|
|
|
|
|
|
# This is obvious. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
*name{CODE} = $code_ref; # Setting code object. |
99
|
|
|
|
|
|
|
# THIS CODE DOES NOT WORK!! |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
*name = $code_ref; # This code works... |
103
|
|
|
|
|
|
|
# Isn't it funny? |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The other problem is readability of the code. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
I think that inconsistency of the glob notation is making readability |
108
|
|
|
|
|
|
|
of the code little bit difficult. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Therefore I wrote this module to provide alternative way of accessing |
111
|
|
|
|
|
|
|
to the values of a symbol. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
By using this module, above examples can be wrote as below. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
use Symbol::Values; |
116
|
|
|
|
|
|
|
my $sym = Symbol::Values->new('name'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$code_ref = $sym->code; # Getting code object. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$sym->code = $code_ref; # Setting code object. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
I hope this module makes your code more readable. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item $obj = CLASS->new($symbol_name_or_glob); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Constructor. You can pass name of symbol like "my_var" or |
134
|
|
|
|
|
|
|
glob like *my_var as argument. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
If the passed argument(glob or name of symbol) was not qualified |
137
|
|
|
|
|
|
|
by package name, it will be qualified by current package name. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
package main; |
140
|
|
|
|
|
|
|
use Symbol::Values; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
our $a = 1; |
143
|
|
|
|
|
|
|
my $obj; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$obj = Symbol::Values->new('a'); # name of symbol. |
146
|
|
|
|
|
|
|
$obj = Symbol::Values->new('main::a'); # same as above. |
147
|
|
|
|
|
|
|
$obj = Symbol::Values->new(*a); # glob. |
148
|
|
|
|
|
|
|
$obj = Symbol::Values->new(*main::a); # same as above. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
There is alternative way of using "new" method: |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
use Symbol::Values 'symbol'; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $obj = symbol($symbol_name_or_glob); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This function "symbol" is not exported by default, so if you prefer to use |
157
|
|
|
|
|
|
|
this syntactic sugar, you should import it explicitly. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub new { |
162
|
12
|
100
|
|
12
|
1
|
654
|
if ($_[0] eq __PACKAGE__) { |
163
|
4
|
|
|
|
|
7
|
shift @_; |
164
|
|
|
|
|
|
|
} |
165
|
12
|
|
|
|
|
27
|
my $glob_or_sym = $_[0]; |
166
|
12
|
|
|
|
|
15
|
my $r_glob; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# no argument |
169
|
12
|
50
|
|
|
|
50
|
if (! $glob_or_sym) { |
|
|
100
|
|
|
|
|
|
170
|
0
|
|
|
|
|
0
|
$r_glob = Symbol::gensym(); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# glob was passed |
174
|
|
|
|
|
|
|
} elsif (ref(\$glob_or_sym) eq 'GLOB') { |
175
|
5
|
|
|
|
|
9
|
$r_glob = \$_[0]; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# name was passed |
178
|
|
|
|
|
|
|
} else { |
179
|
|
|
|
|
|
|
|
180
|
7
|
|
|
|
|
35
|
$glob_or_sym =~ m/\*?(?:(.*)::)?(.+)$/o; |
181
|
7
|
|
|
|
|
17
|
my $pkg = $1; |
182
|
7
|
|
|
|
|
15
|
my $name = $2; |
183
|
|
|
|
|
|
|
|
184
|
7
|
100
|
|
|
|
19
|
unless ($pkg) { |
185
|
6
|
|
|
|
|
40
|
$pkg = (caller(0))[0]; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
7
|
|
|
|
|
15
|
my $new_symbol = 0; |
190
|
|
|
|
|
|
|
{ |
191
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1054
|
|
|
7
|
|
|
|
|
10
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# try to get the glob from symbol table |
194
|
7
|
|
|
|
|
28
|
$r_glob = exists ${"${pkg}::"}{$name} |
|
3
|
|
|
|
|
8
|
|
195
|
7
|
100
|
|
|
|
9
|
? \${"${pkg}::"}{$name} : undef; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# create new name if it is not name of special variable. |
198
|
7
|
100
|
|
|
|
24
|
unless ($r_glob) { |
199
|
4
|
|
|
|
|
7
|
my $orig_exp = $@; |
200
|
4
|
|
|
|
|
247
|
$r_glob = eval "package $pkg; \\\*{$name}"; |
201
|
4
|
|
|
|
|
13
|
$@ = $orig_exp; |
202
|
4
|
50
|
|
|
|
4
|
$new_symbol = 1 if exists ${"${pkg}::"}{$name}; |
|
4
|
|
|
|
|
18
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Fatal error |
207
|
7
|
100
|
|
|
|
2543
|
unless(defined $r_glob) { |
208
|
1
|
|
|
|
|
141
|
croak "Invalid name name \"$glob_or_sym\": possible typo"; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# warn if new symbol |
212
|
6
|
50
|
|
|
|
16
|
if ($new_symbol) { |
213
|
0
|
|
|
|
|
0
|
warnings::warnif "Name \"${pkg}::${name}\" created: possible typo"; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
11
|
|
|
|
|
1449
|
bless [$r_glob] |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
*symbol = \&new; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item $scalar_ref = $obj->scalar_ref; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Get scalar object in the symbol. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
You can also assign new scalar object to a symbol. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $new_value = "something new"; |
229
|
|
|
|
|
|
|
$obj->scalar_ref = \$new_value; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub scalar_ref : lvalue { |
234
|
18
|
|
|
18
|
1
|
965
|
my $r_glob = $_[0]->[0]; |
235
|
18
|
|
|
|
|
18
|
my $ret; |
236
|
18
|
|
|
|
|
63
|
tie $ret, '__TiedSymbol_Scalar', $r_glob; |
237
|
18
|
|
|
|
|
65
|
$ret |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item $scalar = $obj->scalar; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Get scalar value in the symbol. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
You can also assign new scalar value to a symbol. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $new_value = "something new"; |
247
|
|
|
|
|
|
|
$obj->scalar = $new_value; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub scalar : lvalue { |
252
|
8
|
|
|
8
|
1
|
12
|
${$_[0]->scalar_ref} |
|
8
|
|
|
|
|
18
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item $array_ref = $obj->array_ref; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Get array object in the symbol. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
You can also assign new array object to a symbol. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
my @new_value = ("something", "new"); |
263
|
|
|
|
|
|
|
$obj->array_ref = \@new_value; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub array_ref : lvalue { |
268
|
28
|
|
|
28
|
1
|
872
|
my $r_glob = $_[0]->[0]; |
269
|
28
|
|
|
|
|
31
|
my $ret; |
270
|
28
|
|
|
|
|
89
|
tie $ret, '__TiedSymbol_Array', $r_glob; |
271
|
28
|
|
|
|
|
68
|
$ret |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item @array = $obj->array; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Get array value in the symbol as reference. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
You can also assign new array value to a symbol. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
my @new_value = ("something", "new"); |
281
|
|
|
|
|
|
|
($obj->array) = @new_value; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
NOTE: You have to call array method in list context when you assign |
284
|
|
|
|
|
|
|
new value. |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub array : lvalue { |
289
|
5
|
|
|
5
|
1
|
15
|
my $r_glob = $_[0]->[0]; |
290
|
5
|
|
|
|
|
5
|
my $ret; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# create new array value if not exists. |
293
|
5
|
100
|
|
|
|
9
|
unless (defined $_[0]->array_ref) { |
294
|
1
|
|
|
|
|
2
|
my @new; |
295
|
1
|
|
|
|
|
3
|
$_[0]->array_ref = \@new; |
296
|
1
|
|
|
|
|
2
|
*{$r_glob} =~ /^\*(.*)$/; |
|
1
|
|
|
|
|
6
|
|
297
|
1
|
|
|
|
|
2
|
my $name = $1; |
298
|
1
|
|
|
|
|
91
|
warnings::warnif('Symbol::Values', |
299
|
|
|
|
|
|
|
"New array \"\@${name}\" created: possible typo"); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
5
|
100
|
|
|
|
16
|
tie $ret, '__TiedSymbol_Constant', scalar @{$_[0]->array_ref} unless wantarray; |
|
1
|
|
|
|
|
95
|
|
303
|
|
|
|
|
|
|
|
304
|
5
|
50
|
|
|
|
7
|
*{$r_glob} = [] unless defined *{$r_glob}{ARRAY}; |
|
0
|
|
|
|
|
0
|
|
|
5
|
|
|
|
|
12
|
|
305
|
|
|
|
|
|
|
|
306
|
5
|
100
|
|
|
|
12
|
wantarray ? @{$_[0]->array_ref} : $ret |
|
4
|
|
|
|
|
9
|
|
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=item $hash_ref = $obj->hash_ref; |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
Get hash object in the symbol. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
You can also assign new hash object to a symbol. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
my %new_value = ("something" => "new"); |
316
|
|
|
|
|
|
|
$obj->hash_ref = \%new_value; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=cut |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub hash_ref : lvalue { |
321
|
20
|
|
|
20
|
1
|
916
|
my $r_glob = $_[0]->[0]; |
322
|
20
|
|
|
|
|
29
|
my $ret; |
323
|
20
|
|
|
|
|
64
|
tie $ret, '__TiedSymbol_Hash', $r_glob; |
324
|
20
|
|
|
|
|
56
|
$ret |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=item %hash = $obj->hash; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Get hash value in the symbol. |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
You can also assign new hash value to a symbol. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
my %new_value = ("something" => "new"); |
334
|
|
|
|
|
|
|
($obj->hash) = %new_value; |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
NOTE: You have to call hash method in list context when you assign |
337
|
|
|
|
|
|
|
new value. |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=cut |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub hash : lvalue { |
342
|
3
|
|
|
3
|
1
|
620
|
my $r_glob = $_[0]->[0]; |
343
|
3
|
|
|
|
|
5
|
my $ret; |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
# create new hash value if not exists. |
346
|
3
|
100
|
|
|
|
9
|
unless (defined $_[0]->hash_ref) { |
347
|
1
|
|
|
|
|
2
|
my %new; |
348
|
1
|
|
|
|
|
4
|
$_[0]->hash_ref = \%new; |
349
|
1
|
|
|
|
|
4
|
*{$r_glob} =~ /^\*(.*)$/; |
|
1
|
|
|
|
|
7
|
|
350
|
1
|
|
|
|
|
4
|
my $name = $1; |
351
|
1
|
|
|
|
|
92
|
warnings::warnif('Symbol::Values', |
352
|
|
|
|
|
|
|
"New hash \"\%${name}\" created: possible typo"); |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
3
|
100
|
|
|
|
13
|
tie $ret, '__TiedSymbol_Constant', scalar %{$_[0]->hash_ref} unless wantarray; |
|
1
|
|
|
|
|
3
|
|
356
|
|
|
|
|
|
|
|
357
|
3
|
50
|
|
|
|
6
|
*{$r_glob} = {} unless defined *{$r_glob}{HASH}; |
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
8
|
|
358
|
|
|
|
|
|
|
|
359
|
3
|
100
|
|
|
|
7
|
wantarray ? %{$_[0]->hash_ref} : $ret |
|
2
|
|
|
|
|
6
|
|
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=item $code = $obj->code; |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
Get code object in the symbol as reference. |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
use Symbol::Values 'symbol'; |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
sub my_func { |
369
|
|
|
|
|
|
|
print "my_func called.\n"; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
my $sub = symbol('my_func')->code; # my $sub = \&my_func; |
373
|
|
|
|
|
|
|
$sub->(); # => my_func called. |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
You can also assign new code object to a symbol. |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
symbol('my_func')->code = sub { print "modified code called.\n" }; |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
my_func(); # => modified code called. |
380
|
|
|
|
|
|
|
$sub->(); # => my_func called. |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=cut |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub code : lvalue { |
385
|
10
|
|
|
10
|
1
|
1186
|
my $r_glob = $_[0]->[0]; |
386
|
10
|
|
|
|
|
12
|
my $ret; |
387
|
10
|
|
|
|
|
41
|
tie $ret, '__TiedSymbol_Code', $r_glob; |
388
|
10
|
|
|
|
|
39
|
$ret |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
=item $io = $obj->io; |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
Get IO object in the symbol. |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
You can also assign new io object to a symbol. |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
use Symbol; |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
my $obj = Symbol::Values->new('io_sym'); |
400
|
|
|
|
|
|
|
my $io_obj = geniosym(); |
401
|
|
|
|
|
|
|
$obj->io = $io_obj; |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=cut |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
sub io : lvalue { |
406
|
7
|
|
|
7
|
1
|
1146
|
my $r_glob = $_[0]->[0]; |
407
|
7
|
|
|
|
|
9
|
my $ret; |
408
|
7
|
|
|
|
|
28
|
tie $ret, '__TiedSymbol_IO', $r_glob; |
409
|
7
|
|
|
|
|
26
|
$ret |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=item $glob = $obj->glob; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
Get glob object in the symbol. |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
You can also assign new glob object to a symbol. |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
use Symbol::Values 'symbol'; |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
our $var1 = 1; |
421
|
|
|
|
|
|
|
our $var2 = 2; |
422
|
|
|
|
|
|
|
symbol('var2')->glob = symbol('var1')->glob; # *var2 = *var1 |
423
|
|
|
|
|
|
|
print "$var2\n"; # => 2 |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
=cut |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
sub glob : lvalue { |
428
|
8
|
|
|
8
|
1
|
1685
|
my $r_glob = $_[0]->[0]; |
429
|
8
|
|
|
|
|
8
|
my $ret; |
430
|
8
|
|
|
|
|
30
|
tie $ret, '__TiedSymbol_Glob', $r_glob; |
431
|
8
|
|
|
|
|
24
|
$ret |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
=item $format = $obj->format; |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
Get format object in the symbol. |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
You can also assign new format object to a symbol. |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
format my_fmt1 = |
441
|
|
|
|
|
|
|
...... |
442
|
|
|
|
|
|
|
. |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
# alternate way of '*my_fmt2 = *my_fmt1{FORMAT}'. |
445
|
|
|
|
|
|
|
symbol('my_fmt2')->format = symbol('my_fmt1')->format; |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=cut |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
sub format : lvalue { |
450
|
6
|
|
|
6
|
1
|
864
|
my $r_glob = $_[0]->[0]; |
451
|
6
|
|
|
|
|
8
|
my $ret; |
452
|
6
|
|
|
|
|
20
|
tie $ret, '__TiedSymbol_Format', $r_glob; |
453
|
6
|
|
|
|
|
25
|
$ret |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=back |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=head1 EXPORT |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
None by default. |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=head1 BUGS/LIMITATIONS |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=over 4 |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=item Speed |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
The cost of getting consistency of notation and readability is time. |
469
|
|
|
|
|
|
|
So if the response is very important problem of your project, please consider |
470
|
|
|
|
|
|
|
to use funny glob notation. |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=item Taste |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
If you're loving default glob notation, just ignore this module. |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=back |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=head1 SEE ALSO |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=over 4 |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=item perlref |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
Generic information about symbol table mechanism in perl. |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=item Hook::LexWrap |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
If you want to override some existing functions/methods, |
489
|
|
|
|
|
|
|
it is very nice idea to consult "Hook::LexWrap". |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=item t/Symbol-Values.t |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
Test file "t/Symbol-Values.t" in the distribution of this module -- This file provides you some example of usage. |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=back |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
=head1 AUTHOR |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
Keitaro Miyazaki, Ekmiyazaki@cpan.orgE |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
Copyright (C) 2005 by Keitaro Miyazaki |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
506
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
=cut |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
#************************************************************************* |
513
|
|
|
|
|
|
|
# |
514
|
|
|
|
|
|
|
# Subcontractors |
515
|
|
|
|
|
|
|
# |
516
|
|
|
|
|
|
|
#************************************************************************* |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
520
|
|
|
|
|
|
|
# Base class |
521
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
522
|
|
|
|
|
|
|
package __TiedSymbol; |
523
|
|
|
|
|
|
|
|
524
|
1
|
|
|
1
|
|
1050
|
use Tie::Scalar; |
|
1
|
|
|
|
|
593
|
|
|
1
|
|
|
|
|
24
|
|
525
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
526
|
|
|
|
|
|
|
|
527
|
1
|
|
|
1
|
|
4
|
use base ("Tie::Scalar"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
199
|
|
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
sub TIESCALAR { |
530
|
97
|
|
|
97
|
|
173
|
my ($class, $r_glob) = @_; |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# field 'slot' must be specified in sublcass. |
533
|
97
|
|
|
|
|
241
|
my $self = { |
534
|
|
|
|
|
|
|
r_glob => $r_glob, |
535
|
|
|
|
|
|
|
}; |
536
|
|
|
|
|
|
|
|
537
|
97
|
|
|
|
|
227
|
bless $self, $class; |
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
|
540
|
0
|
|
|
0
|
|
0
|
sub DESTROY { |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
sub FETCH { |
544
|
98
|
|
|
98
|
|
113
|
my $self = shift; |
545
|
98
|
|
|
|
|
98
|
my $slot = shift; |
546
|
98
|
|
|
|
|
125
|
my $r_glob = $self->{r_glob}; |
547
|
|
|
|
|
|
|
|
548
|
98
|
|
|
|
|
89
|
my $ret; |
549
|
|
|
|
|
|
|
|
550
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
551
|
98
|
|
|
|
|
93
|
$ret = *{$r_glob}{$self->{slot}}; |
|
98
|
|
|
|
|
172
|
|
552
|
1
|
|
|
1
|
|
17
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
553
|
|
|
|
|
|
|
|
554
|
98
|
|
|
|
|
438
|
$ret |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
0
|
|
|
0
|
|
0
|
sub STORE { |
558
|
|
|
|
|
|
|
# Should be overridden in subclass |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
562
|
|
|
|
|
|
|
# SCALAR |
563
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
564
|
|
|
|
|
|
|
package __TiedSymbol_Scalar; |
565
|
1
|
|
|
1
|
|
4
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
631
|
|
566
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
186
|
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
sub TIESCALAR { |
569
|
18
|
|
|
18
|
|
22
|
my $class = shift; |
570
|
18
|
|
|
|
|
66
|
my $self = $class->SUPER::TIESCALAR(@_); |
571
|
18
|
|
|
|
|
41
|
$self->{slot} = 'SCALAR'; |
572
|
18
|
|
|
|
|
38
|
$self |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
sub STORE { |
576
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
577
|
4
|
|
|
|
|
7
|
my $new_val = shift; |
578
|
|
|
|
|
|
|
|
579
|
4
|
|
|
|
|
7
|
my $r_glob = $self->{r_glob}; |
580
|
|
|
|
|
|
|
|
581
|
4
|
100
|
|
|
|
14
|
if (ref(\$new_val) eq "GLOB") { |
582
|
1
|
|
|
|
|
2
|
$new_val = *{$new_val}{SCALAR}; |
|
1
|
|
|
|
|
3
|
|
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
|
585
|
4
|
100
|
100
|
|
|
35
|
if (defined($new_val) && (ref($new_val) ne 'SCALAR')) { |
586
|
1
|
|
|
|
|
259
|
croak "Can't assign non scalar object to value of scalar_ref"; |
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
|
589
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
590
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
61
|
|
591
|
3
|
100
|
|
|
|
9
|
if (defined $new_val) { |
592
|
2
|
|
|
|
|
3
|
*{$r_glob} = $new_val; |
|
2
|
|
|
|
|
4
|
|
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
} else { |
595
|
1
|
|
|
|
|
2
|
undef ${*{$r_glob}{SCALAR}}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
596
|
|
|
|
|
|
|
} |
597
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
598
|
1
|
|
|
1
|
|
4
|
use strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
599
|
|
|
|
|
|
|
|
600
|
3
|
|
|
|
|
10
|
$new_val |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
604
|
|
|
|
|
|
|
# ARRAY |
605
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
606
|
|
|
|
|
|
|
package __TiedSymbol_Array; |
607
|
1
|
|
|
1
|
|
4
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
447
|
|
608
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
176
|
|
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
sub TIESCALAR { |
611
|
28
|
|
|
28
|
|
36
|
my $class = shift; |
612
|
28
|
|
|
|
|
81
|
my $self = $class->SUPER::TIESCALAR(@_); |
613
|
28
|
|
|
|
|
65
|
$self->{slot} = 'ARRAY'; |
614
|
28
|
|
|
|
|
54
|
$self |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
sub STORE { |
618
|
5
|
|
|
5
|
|
11
|
my $self = shift; |
619
|
5
|
|
|
|
|
7
|
my $new_val = shift; |
620
|
|
|
|
|
|
|
|
621
|
5
|
|
|
|
|
8
|
my $r_glob = $self->{r_glob}; |
622
|
|
|
|
|
|
|
|
623
|
5
|
100
|
|
|
|
19
|
if (ref(\$new_val) eq "GLOB") { |
624
|
1
|
|
|
|
|
2
|
$new_val = *{$new_val}{ARRAY}; |
|
1
|
|
|
|
|
3
|
|
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
5
|
100
|
100
|
|
|
26
|
if (defined($new_val) && (ref($new_val) ne 'ARRAY')) { |
628
|
1
|
|
|
|
|
175
|
croak "Can't assign non array object to value of array_ref"; |
629
|
|
|
|
|
|
|
} |
630
|
|
|
|
|
|
|
|
631
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
632
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
633
|
4
|
100
|
|
|
|
19
|
if (defined $new_val) { |
634
|
3
|
|
|
|
|
3
|
*{$r_glob} = $new_val; |
|
3
|
|
|
|
|
7
|
|
635
|
|
|
|
|
|
|
} else { |
636
|
1
|
|
|
|
|
2
|
undef @{*{$r_glob}{ARRAY}}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
637
|
|
|
|
|
|
|
} |
638
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
639
|
1
|
|
|
1
|
|
6
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
640
|
|
|
|
|
|
|
|
641
|
4
|
|
|
|
|
13
|
$new_val |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
645
|
|
|
|
|
|
|
# HASH |
646
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
647
|
|
|
|
|
|
|
package __TiedSymbol_Hash; |
648
|
1
|
|
|
1
|
|
5
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
381
|
|
649
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
164
|
|
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub TIESCALAR { |
652
|
20
|
|
|
20
|
|
29
|
my $class = shift; |
653
|
20
|
|
|
|
|
62
|
my $self = $class->SUPER::TIESCALAR(@_); |
654
|
20
|
|
|
|
|
44
|
$self->{slot} = 'HASH'; |
655
|
20
|
|
|
|
|
44
|
$self |
656
|
|
|
|
|
|
|
} |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
sub STORE { |
659
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
660
|
5
|
|
|
|
|
7
|
my $new_val = shift; |
661
|
|
|
|
|
|
|
|
662
|
5
|
|
|
|
|
11
|
my $r_glob = $self->{r_glob}; |
663
|
|
|
|
|
|
|
|
664
|
5
|
100
|
|
|
|
18
|
if (ref(\$new_val) eq "GLOB") { |
665
|
1
|
|
|
|
|
31
|
$new_val = *{$new_val}{HASH}; |
|
1
|
|
|
|
|
4
|
|
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
|
668
|
5
|
100
|
100
|
|
|
29
|
if (defined($new_val) && (ref($new_val) ne 'HASH')) { |
669
|
1
|
|
|
|
|
169
|
croak "Can't assign non hash object to value of symbol_hash_ref"; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
673
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
674
|
4
|
100
|
|
|
|
10
|
if (defined $new_val) { |
675
|
3
|
|
|
|
|
4
|
*{$r_glob} = $new_val; |
|
3
|
|
|
|
|
9
|
|
676
|
|
|
|
|
|
|
} else { |
677
|
1
|
|
|
|
|
2
|
undef %{*{$r_glob}{HASH}}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
678
|
|
|
|
|
|
|
} |
679
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
680
|
1
|
|
|
1
|
|
5
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
681
|
|
|
|
|
|
|
|
682
|
4
|
|
|
|
|
13
|
$new_val |
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
686
|
|
|
|
|
|
|
# CODE |
687
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
688
|
|
|
|
|
|
|
package __TiedSymbol_Code; |
689
|
1
|
|
|
1
|
|
5
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
399
|
|
690
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
154
|
|
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
sub TIESCALAR { |
693
|
10
|
|
|
10
|
|
17
|
my $class = shift; |
694
|
10
|
|
|
|
|
37
|
my $self = $class->SUPER::TIESCALAR(@_); |
695
|
10
|
|
|
|
|
27
|
$self->{slot} = 'CODE'; |
696
|
10
|
|
|
|
|
23
|
$self |
697
|
|
|
|
|
|
|
} |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
sub STORE { |
700
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
701
|
4
|
|
|
|
|
8
|
my $new_val = shift; |
702
|
|
|
|
|
|
|
|
703
|
4
|
|
|
|
|
7
|
my $r_glob = $self->{r_glob}; |
704
|
|
|
|
|
|
|
|
705
|
4
|
100
|
|
|
|
15
|
if (ref(\$new_val) eq "GLOB") { |
706
|
1
|
|
|
|
|
2
|
$new_val = *{$new_val}{CODE}; |
|
1
|
|
|
|
|
3
|
|
707
|
|
|
|
|
|
|
} |
708
|
|
|
|
|
|
|
|
709
|
4
|
100
|
100
|
|
|
22
|
if (defined($new_val) && (ref($new_val) ne 'CODE')) { |
710
|
1
|
|
|
|
|
155
|
croak "Can't assign non code object to value of code"; |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
28
|
|
714
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
715
|
3
|
100
|
|
|
|
9
|
if (defined $new_val) { |
716
|
2
|
|
|
|
|
2
|
*{$r_glob} = $new_val; |
|
2
|
|
|
|
|
15
|
|
717
|
|
|
|
|
|
|
} else { |
718
|
1
|
|
|
|
|
2
|
undef &{$r_glob}; |
|
1
|
|
|
|
|
7
|
|
719
|
|
|
|
|
|
|
} |
720
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
721
|
1
|
|
|
1
|
|
3
|
use strict 'refs'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
44
|
|
722
|
|
|
|
|
|
|
|
723
|
3
|
|
|
|
|
10
|
$new_val |
724
|
|
|
|
|
|
|
} |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
727
|
|
|
|
|
|
|
# IO |
728
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
729
|
|
|
|
|
|
|
package __TiedSymbol_IO; |
730
|
1
|
|
|
1
|
|
3
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
488
|
|
731
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
255
|
|
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
sub TIESCALAR { |
734
|
7
|
|
|
7
|
|
11
|
my $class = shift; |
735
|
7
|
|
|
|
|
33
|
my $self = $class->SUPER::TIESCALAR(@_); |
736
|
7
|
|
|
|
|
22
|
$self->{slot} = 'IO'; |
737
|
7
|
|
|
|
|
20
|
$self |
738
|
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
sub STORE { |
741
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
742
|
3
|
|
|
|
|
6
|
my $new_val = shift; |
743
|
|
|
|
|
|
|
|
744
|
3
|
|
|
|
|
5
|
my $r_glob = $self->{r_glob}; |
745
|
|
|
|
|
|
|
|
746
|
3
|
100
|
|
|
|
12
|
if (ref(\$new_val) eq "GLOB") { |
747
|
1
|
|
|
|
|
1
|
$new_val = *{$new_val}{IO}; |
|
1
|
|
|
|
|
3
|
|
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
3
|
|
|
|
|
7
|
my $orig_exp = $@; |
751
|
3
|
50
|
66
|
|
|
10
|
if (defined($new_val) && ! eval { $new_val->isa('IO') }) { |
|
2
|
|
|
|
|
28
|
|
752
|
0
|
|
|
|
|
0
|
$@ = $orig_exp; |
753
|
0
|
|
|
|
|
0
|
croak "Can't assign non io object to value of io"; |
754
|
|
|
|
|
|
|
} |
755
|
|
|
|
|
|
|
|
756
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
757
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
758
|
3
|
100
|
|
|
|
10
|
if (defined $new_val) { |
759
|
2
|
|
|
|
|
2
|
*{$r_glob} = $new_val; |
|
2
|
|
|
|
|
8
|
|
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
} else { |
762
|
1
|
|
|
|
|
166
|
croak "Can't assign value \"undef\" to value of io.\n"; |
763
|
|
|
|
|
|
|
} |
764
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
765
|
1
|
|
|
1
|
|
4
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
766
|
|
|
|
|
|
|
|
767
|
2
|
|
|
|
|
6
|
$new_val |
768
|
|
|
|
|
|
|
} |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
771
|
|
|
|
|
|
|
# Format |
772
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
773
|
|
|
|
|
|
|
package __TiedSymbol_Format; |
774
|
1
|
|
|
1
|
|
5
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
520
|
|
775
|
1
|
|
|
1
|
|
20
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
167
|
|
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
sub TIESCALAR { |
778
|
6
|
|
|
6
|
|
9
|
my $class = shift; |
779
|
6
|
|
|
|
|
24
|
my $self = $class->SUPER::TIESCALAR(@_); |
780
|
6
|
|
|
|
|
17
|
$self->{slot} = 'FORMAT'; |
781
|
6
|
|
|
|
|
21
|
$self |
782
|
|
|
|
|
|
|
} |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
sub STORE { |
785
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
786
|
4
|
|
|
|
|
5
|
my $new_val = shift; |
787
|
|
|
|
|
|
|
|
788
|
4
|
|
|
|
|
7
|
my $r_glob = $self->{r_glob}; |
789
|
|
|
|
|
|
|
|
790
|
4
|
100
|
|
|
|
14
|
if (ref(\$new_val) eq "GLOB") { |
791
|
1
|
|
|
|
|
2
|
$new_val = *{$new_val}{FORMAT}; |
|
1
|
|
|
|
|
4
|
|
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
|
794
|
4
|
100
|
100
|
|
|
25
|
if (defined($new_val) && !(ref($new_val) eq 'FORMAT')) { |
795
|
1
|
|
|
|
|
115
|
croak "Can't assign non format object to value of format"; |
796
|
|
|
|
|
|
|
} |
797
|
|
|
|
|
|
|
|
798
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
799
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
800
|
3
|
100
|
|
|
|
7
|
if (defined $new_val) { |
801
|
2
|
|
|
|
|
3
|
*{$r_glob} = $new_val; |
|
2
|
|
|
|
|
11
|
|
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
} else { |
804
|
1
|
|
|
|
|
170
|
croak "Can't assign value \"undef\" to value of format.\n"; |
805
|
|
|
|
|
|
|
} |
806
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
807
|
1
|
|
|
1
|
|
5
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
808
|
|
|
|
|
|
|
|
809
|
2
|
|
|
|
|
6
|
$new_val |
810
|
|
|
|
|
|
|
} |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
813
|
|
|
|
|
|
|
# GLOB |
814
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
815
|
|
|
|
|
|
|
package __TiedSymbol_Glob; |
816
|
1
|
|
|
1
|
|
5
|
use base ("__TiedSymbol"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
468
|
|
817
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
198
|
|
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
sub TIESCALAR { |
820
|
8
|
|
|
8
|
|
9
|
my $class = shift; |
821
|
8
|
|
|
|
|
28
|
my $self = $class->SUPER::TIESCALAR(@_); |
822
|
8
|
|
|
|
|
18
|
$self->{slot} = 'GLOB'; |
823
|
8
|
|
|
|
|
15
|
$self |
824
|
|
|
|
|
|
|
} |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
sub FETCH { |
827
|
4
|
|
|
4
|
|
5
|
my $self = shift; |
828
|
|
|
|
|
|
|
|
829
|
4
|
|
|
|
|
10
|
my $ret = $self->SUPER::FETCH(@_); |
830
|
|
|
|
|
|
|
|
831
|
4
|
|
|
|
|
26
|
*$ret |
832
|
|
|
|
|
|
|
} |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
sub STORE { |
835
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
836
|
4
|
|
|
|
|
7
|
my $new_val = $_[0]; |
837
|
|
|
|
|
|
|
|
838
|
4
|
|
|
|
|
5
|
my $r_glob = $self->{r_glob}; |
839
|
|
|
|
|
|
|
|
840
|
4
|
100
|
100
|
|
|
22
|
if (defined($new_val) && (ref(\$new_val) ne 'GLOB')) { |
841
|
1
|
|
|
|
|
162
|
croak "Can't assign non glob object to value of glob"; |
842
|
|
|
|
|
|
|
} |
843
|
|
|
|
|
|
|
|
844
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
845
|
3
|
100
|
|
|
|
12
|
if (defined $new_val) { |
846
|
|
|
|
|
|
|
|
847
|
2
|
|
|
|
|
4
|
*{$r_glob} = \$_[0]; |
|
2
|
|
|
|
|
15
|
|
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
} else { |
850
|
1
|
|
|
|
|
2
|
undef *{$r_glob}; |
|
1
|
|
|
|
|
4
|
|
851
|
|
|
|
|
|
|
} |
852
|
1
|
|
|
1
|
|
5
|
use strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
853
|
|
|
|
|
|
|
|
854
|
3
|
|
|
|
|
11
|
$new_val |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
package __TiedSymbol_Constant; |
858
|
|
|
|
|
|
|
|
859
|
1
|
|
|
1
|
|
4
|
use Tie::Scalar; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
16
|
|
860
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
66
|
|
861
|
|
|
|
|
|
|
|
862
|
1
|
|
|
1
|
|
6
|
use base ("Tie::Scalar"); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
194
|
|
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
sub TIESCALAR { |
865
|
2
|
|
|
2
|
|
3
|
my ($class, $value) = @_; |
866
|
2
|
|
|
|
|
6
|
bless \$value, $class; |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
} |
869
|
|
|
|
|
|
|
|
870
|
0
|
|
|
0
|
|
0
|
sub DESTROY { |
871
|
|
|
|
|
|
|
} |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
sub FETCH { |
874
|
0
|
|
|
0
|
|
0
|
my $r_value = shift; |
875
|
0
|
|
|
|
|
0
|
$$r_value |
876
|
|
|
|
|
|
|
} |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
sub STORE { |
879
|
2
|
|
|
2
|
|
253
|
croak "Can't modify list value in scalar context"; |
880
|
|
|
|
|
|
|
} |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
1 |