line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
#Reference.pm |
3
|
|
|
|
|
|
|
#Last Change: 2009-28-01 |
4
|
|
|
|
|
|
|
#Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch |
5
|
|
|
|
|
|
|
#Version 0.3 |
6
|
|
|
|
|
|
|
#################### |
7
|
|
|
|
|
|
|
#This file is part of the sofu.pm project, a parser library for an all-purpose |
8
|
|
|
|
|
|
|
#ASCII file format. More information can be found on the project web site |
9
|
|
|
|
|
|
|
#at http://sofu.sourceforge.net/ . |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
#sofu.pm is published under the terms of the MIT license, which basically means |
12
|
|
|
|
|
|
|
#"Do with it whatever you want". For more information, see the license.txt |
13
|
|
|
|
|
|
|
#file that should be enclosed with libsofu distributions. A copy of the license |
14
|
|
|
|
|
|
|
#is (at the time of this writing) also available at |
15
|
|
|
|
|
|
|
#http://www.opensource.org/licenses/mit-license.php . |
16
|
|
|
|
|
|
|
############################################################################### |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Data::Sofu::Reference - A Sofu Reference |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Provides a interface similar to the original SofuD (sofu.sf.net). |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
References present a transparent interface to the object referenced. Normally they shouldn't even bother you one bit. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 Synopsis |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
require Data::Sofu::Map; |
32
|
|
|
|
|
|
|
require Data::Sofu::Reference; |
33
|
|
|
|
|
|
|
my $map = Data::Sofu::Map->new(); |
34
|
|
|
|
|
|
|
$map->setAttribute("myself",Data::Sofu::Reference->new($map)); #Reference to itself. |
35
|
|
|
|
|
|
|
$map->map("myself"); #Will return $map not the Reference. |
36
|
|
|
|
|
|
|
$map->object("myself")->asReference(); #Will return the Reference. |
37
|
|
|
|
|
|
|
$map->object("myself")->asMap(); #will return the Map. |
38
|
|
|
|
|
|
|
$map->object("myself")->isMap(); #True |
39
|
|
|
|
|
|
|
$map->map("myself")->isMap(); #Also true |
40
|
|
|
|
|
|
|
$map->object("myself")->isReference(); #True |
41
|
|
|
|
|
|
|
$map->map("myself")->isReference(); #false (you skipped the reference when using map()); |
42
|
|
|
|
|
|
|
#You can also: |
43
|
|
|
|
|
|
|
my $map = Data::Sofu::Map->new(); |
44
|
|
|
|
|
|
|
$map->setAttribute("myself",$map); #Will be converted to Reference as soon as it is written to a file or string. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNTAX |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This Module is pure OO, exports nothing |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Data::Sofu::Reference; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
98
|
|
|
3
|
|
|
|
|
108
|
|
56
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
189
|
|
57
|
|
|
|
|
|
|
require Data::Sofu::Object; |
58
|
|
|
|
|
|
|
our @ISA = qw/Data::Sofu::Object/; |
59
|
|
|
|
|
|
|
our $VERSION="0.3"; |
60
|
3
|
|
|
3
|
|
22
|
use vars qw/$AUTOLOAD/; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
9838
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Also look at C for methods, cause Reference inherits from it |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 new([DATA]) |
67
|
|
|
|
|
|
|
Creates a new C and returns it |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$ref = Data::Sofu::Reference->new("->myself"); #Tree form, not valid (just for saving data) |
70
|
|
|
|
|
|
|
my $map = Data::Sofu::Map->new(); |
71
|
|
|
|
|
|
|
$ref = Data::Sofu::Reference->new($map); #Valid |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
76
|
179
|
|
|
179
|
1
|
390
|
my $self={}; |
77
|
179
|
|
|
|
|
522
|
bless $self,shift; |
78
|
179
|
100
|
|
|
|
505
|
if (@_) { |
79
|
19
|
|
|
|
|
103
|
$self->{Reference}=shift; |
80
|
|
|
|
|
|
|
} |
81
|
179
|
|
|
|
|
533
|
return $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 dangle([Data]) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Changes the target of the Reference to Data |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub dangle { |
91
|
335
|
|
|
335
|
1
|
11618
|
my $self=shift; |
92
|
335
|
|
|
|
|
1386
|
$self->{Reference}=shift; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 valid() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Return 1 if the Reference is there and points to something that is a Data::Sofu::Object |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub valid { |
102
|
357
|
|
|
357
|
1
|
527
|
my $self=shift; |
103
|
357
|
|
|
|
|
874
|
my $r = ref $self->{Reference}; |
104
|
357
|
50
|
66
|
|
|
2947
|
return 1 if $r and $r=~m/Data::Sofu/ and $self->{Reference}->isa("Data::Sofu::Object"); |
|
|
|
66
|
|
|
|
|
105
|
175
|
|
|
|
|
533
|
return 0; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 isValid() |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Return 1 if the Reference is there and points to something that is a Data::Sofu::Object |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub isValid { |
115
|
15
|
|
|
15
|
1
|
23
|
my $self=shift; |
116
|
15
|
|
|
|
|
39
|
my $r = ref $self->{Reference}; |
117
|
15
|
50
|
33
|
|
|
559
|
return 1 if $r and $r=~m/Data::Sofu/ and $self->{Reference}->isa("Data::Sofu::Object"); |
|
|
|
33
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 isReference() |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns 1 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub isReference { |
128
|
188
|
|
|
188
|
1
|
1022
|
return 1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 follow() |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Returns the referenced object, valid or not. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub follow { |
138
|
360
|
|
|
360
|
1
|
497
|
my $self=shift; |
139
|
360
|
|
|
|
|
1814
|
return $self->{Reference}; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 asValue() |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns the referenced objects asValue() call. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Which Returns either the referenced object or throws an exception |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub asValue { |
151
|
3
|
|
|
3
|
1
|
7
|
my $self=shift; |
152
|
3
|
50
|
|
|
|
8
|
die "Invalid Reference" unless $self->isValid(); |
153
|
3
|
|
|
|
|
15
|
return $self->{Reference}->asValue(); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 asMap() |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns the referenced objects asMap() call. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Which Returns either the referenced object or throws an exception |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub asMap { |
165
|
3
|
|
|
3
|
1
|
6
|
my $self=shift; |
166
|
3
|
50
|
|
|
|
9
|
die "Invalid Reference" unless $self->isValid(); |
167
|
3
|
|
|
|
|
14
|
return $self->{Reference}->asMap(); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 asList() |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns the referenced objects asList() call. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Which Returns either the referenced object or throws an exception |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub asList { |
179
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
180
|
0
|
0
|
|
|
|
0
|
die "Invalid Reference" unless $self->isValid(); |
181
|
0
|
|
|
|
|
0
|
return $self->{Reference}->asList(); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 isList() |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns 1 if the Reference is valid and the referenced Object is a List. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub isList { |
191
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
192
|
0
|
|
0
|
|
|
0
|
return $self->isValid() && $self->{Reference}->isList(); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 isValue() |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns 1 if the Reference is valid and the referenced Object is a Value. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub isValue { |
202
|
3
|
|
|
3
|
1
|
9
|
my $self=shift; |
203
|
3
|
|
33
|
|
|
101
|
return $self->isValid() && $self->{Reference}->isValue(); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 isMap() |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns 1 if the Reference is valid and the referenced Object is a Map. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub isMap { |
213
|
6
|
|
|
6
|
1
|
12
|
my $self=shift; |
214
|
6
|
|
33
|
|
|
20
|
return $self->isValid() && $self->{Reference}->isMap(); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 isDefined() |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Returns 1 if the Reference is valid and the referenced Object is defined (i.e. not a C). |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub isDefined { |
224
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
225
|
0
|
|
0
|
|
|
|
return $self->isValid() && $self->{Reference}->isDefined(); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 asReference() |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Returns itself |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub asReference { |
236
|
0
|
|
|
0
|
1
|
|
return shift; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
#Experimental (Work with References as if they were transparent) |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
#sub AUTOLOAD { |
242
|
|
|
|
|
|
|
# my $self=shift; |
243
|
|
|
|
|
|
|
# my $x=$AUTOLOAD; |
244
|
|
|
|
|
|
|
# $x=~s/^.+:://g; |
245
|
|
|
|
|
|
|
# #die $x; |
246
|
|
|
|
|
|
|
# return $self->{Reference}->$x(@_); |
247
|
|
|
|
|
|
|
#} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#sub DESTROY { |
250
|
|
|
|
|
|
|
# my $self=shift; |
251
|
|
|
|
|
|
|
# $self->{Reference}=undef; |
252
|
|
|
|
|
|
|
#} |
253
|
|
|
|
|
|
|
# |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 BUGS |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Referencing something else than a C or derieved will not convert the referenced thing and it will confuse the write() to produce invalid sofu files. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 SEE ALSO |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L, L, L, L, L, L, L |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |