| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Header: /home/fergal/my/cvs/Code-Perl/lib/Code/Perl/Expr.pm,v 1.10 2003/06/17 21:51:25 fergal Exp $ |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
712
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
52
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Code::Perl::Expr; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
109
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
571
|
use Code::Perl::Expr::Scalar; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
31
|
|
|
11
|
1
|
|
|
1
|
|
536
|
use Code::Perl::Expr::Number; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
12
|
1
|
|
|
1
|
|
502
|
use Code::Perl::Expr::String; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
13
|
1
|
|
|
1
|
|
552
|
use Code::Perl::Expr::List; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
14
|
1
|
|
|
1
|
|
615
|
use Code::Perl::Expr::DerefHash; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
34
|
|
|
15
|
1
|
|
|
1
|
|
666
|
use Code::Perl::Expr::DerefArray; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
16
|
1
|
|
|
1
|
|
660
|
use Code::Perl::Expr::CallSub; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
31
|
|
|
17
|
1
|
|
|
1
|
|
703
|
use Code::Perl::Expr::CallMethod; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
18
|
1
|
|
|
1
|
|
645
|
use Code::Perl::Expr::Not; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
26
|
|
|
19
|
1
|
|
|
1
|
|
576
|
use Code::Perl::Expr::Perl; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
20
|
1
|
|
|
1
|
|
561
|
use Code::Perl::Expr::Append; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
33
|
|
|
21
|
1
|
|
|
1
|
|
887
|
use Code::Perl::Expr::Holder; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
22
|
1
|
|
|
1
|
|
653
|
use Code::Perl::Expr::SubName; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
723
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
25
|
|
|
|
|
|
|
easy => [qw( scal number string list derefh derefa calls callm boolnot perl |
|
26
|
|
|
|
|
|
|
append holder subname )], |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT_OK = @{$EXPORT_TAGS{"easy"}}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Code::Perl::Expr - Produce Perl expression from a tree |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Code::Perl::Expr qw( :easy ); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $c = derefh(scal('hash'), calls('getkey')); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
print $c->perl; # ($hash)->{getkey()} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Code::Perl::Expr handles the expressions part of L. It can |
|
46
|
|
|
|
|
|
|
export convenience functions for constructing new Expr objects of all |
|
47
|
|
|
|
|
|
|
available types. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Rather than documenting each available Expression class in it's own file, |
|
50
|
|
|
|
|
|
|
they are documented here, along with easy constructor exported by this |
|
51
|
|
|
|
|
|
|
module. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 EXPRESSION CLASSES |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
C has been removed from the front of the class names, so |
|
56
|
|
|
|
|
|
|
for example C is really C. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 Number |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$class->new(Value => $number); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
number($number); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$number - a number |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Number is for handling numbers. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
number(5)->perl # 5 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub number |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
7
|
|
|
7
|
0
|
5516
|
return Code::Perl::Expr::Number->new( |
|
77
|
|
|
|
|
|
|
Value => shift |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 String |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$class->new(Value => $string); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
string($string); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$string - a string |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
String is for handling strings. It produces a double quoted string, escaped |
|
90
|
|
|
|
|
|
|
so that it will stay on one line |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
string('hello\nworld$')->perl # "hello\nworld\$" |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub string |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
15
|
|
|
15
|
0
|
69
|
return Code::Perl::Expr::String->new( |
|
99
|
|
|
|
|
|
|
Value => shift |
|
100
|
|
|
|
|
|
|
); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 Scalar |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$class->new(Name => $name); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
scal($name); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$name - a string |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This handles a scalar. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
scal("var")->perl # $var |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub scal |
|
118
|
|
|
|
|
|
|
{ |
|
119
|
10
|
|
|
10
|
0
|
280
|
return Code::Perl::Expr::Scalar->new( |
|
120
|
|
|
|
|
|
|
Name => shift |
|
121
|
|
|
|
|
|
|
); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 List |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$class->new(Value => \@exprs); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
list(@exprs); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
@exprs - an array of Expression objects |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
List is for producing a comma separated list of expressions. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
list(scal("v"), string("a"), number(5))->perl # $v, "a", 5 |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub list |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
5
|
|
|
5
|
0
|
28
|
return Code::Perl::Expr::List->new( |
|
141
|
|
|
|
|
|
|
Value => [@_] |
|
142
|
|
|
|
|
|
|
); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 Not |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$class->new(Expr => $expr); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
boolnot($expr); |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$expr - an Expression object. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This applies a logical not to $expr |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
boolnot(scal("is"))->perl # ! $is |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub boolnot |
|
160
|
|
|
|
|
|
|
{ |
|
161
|
2
|
|
|
2
|
0
|
42
|
return Code::Perl::Expr::Not->new( |
|
162
|
|
|
|
|
|
|
Expr => shift, |
|
163
|
|
|
|
|
|
|
); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 Append |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$class->new(Exprs => \@exprs); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
append(@exprs); |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
@exprs - a list of Expression objects. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Append produces code that appends the |
|
175
|
|
|
|
|
|
|
expressions together using Perl's C<.> string append operator. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
append(string("hello"), string(" world"))->perl # "hello"." world"; |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub append |
|
182
|
|
|
|
|
|
|
{ |
|
183
|
1
|
|
|
1
|
0
|
15
|
return Code::Perl::Expr::Append->new( |
|
184
|
|
|
|
|
|
|
Exprs => [@_], |
|
185
|
|
|
|
|
|
|
); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 DerefHash |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
$class->new(Ref => $hash, Key => $key); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
derefh($hash, $key); |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$hash - Expression objects |
|
197
|
|
|
|
|
|
|
$key - Expression objects or string |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
C will turn $key into a String object if it is a string. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
DerefHash is for dereferencing a hash ref. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
derefh(scal("hash"), "key")->perl # $hash->{"key"} |
|
204
|
|
|
|
|
|
|
derefh(scal("hash"), calls("getkey"))->perl # $hash->{getkey()} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub derefh |
|
209
|
|
|
|
|
|
|
{ |
|
210
|
2
|
|
|
2
|
0
|
3
|
my $hash = shift; |
|
211
|
2
|
|
|
|
|
4
|
my $index = shift; |
|
212
|
2
|
100
|
|
|
|
8
|
if (! ref($index)) |
|
213
|
|
|
|
|
|
|
{ |
|
214
|
1
|
|
|
|
|
4
|
$index = string($index); |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
2
|
|
|
|
|
18
|
return Code::Perl::Expr::DerefHash->new( |
|
218
|
|
|
|
|
|
|
Ref => $hash, |
|
219
|
|
|
|
|
|
|
Key => $index |
|
220
|
|
|
|
|
|
|
); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 DerefArray |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$class->new(Ref => $hash, Index => $index); |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
derefa($hash, $index); |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
$hash - an Expression objects |
|
230
|
|
|
|
|
|
|
$index - an Expression object or a number |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
C will turn $index into a Number object if it is a number. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
DerefArray is for dereferencing an array ref. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
derefa(scal("array"), 5)->perl # $array->[5] |
|
237
|
|
|
|
|
|
|
derefa(scal("array"), calls("getindex"))->perl # $array->[getindex()] |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub derefa |
|
242
|
|
|
|
|
|
|
{ |
|
243
|
2
|
|
|
2
|
0
|
3
|
my $hash = shift; |
|
244
|
2
|
|
|
|
|
4
|
my $index = shift; |
|
245
|
2
|
100
|
|
|
|
16
|
if (! ref($index)) |
|
246
|
|
|
|
|
|
|
{ |
|
247
|
1
|
|
|
|
|
3
|
$index = number($index); |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
2
|
|
|
|
|
17
|
return Code::Perl::Expr::DerefArray->new( |
|
251
|
|
|
|
|
|
|
Ref => $hash, |
|
252
|
|
|
|
|
|
|
Index => $index |
|
253
|
|
|
|
|
|
|
); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 SubName |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$class->new(Value => $name); |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
subname($name); |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$name should be a string, naming a subroutine or a method. Used when |
|
263
|
|
|
|
|
|
|
creating a CallSub or CallMethod object. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub subname |
|
268
|
|
|
|
|
|
|
{ |
|
269
|
3
|
|
|
3
|
0
|
23
|
return Code::Perl::Expr::SubName->new( |
|
270
|
|
|
|
|
|
|
Value => shift, |
|
271
|
|
|
|
|
|
|
); |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 CallSub |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
$class->new(SubName => $sub, Args => $args); |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
calls($subname, @args); |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$sub, $args - Expression objects. |
|
281
|
|
|
|
|
|
|
$subname - an Expression object or a string |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
C will turn $subname into a SubName object if it is a string. It |
|
284
|
|
|
|
|
|
|
will wrap @args in a List object. |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
CallSub will produce code to call the subroutine in $sub with passing the |
|
287
|
|
|
|
|
|
|
list in $args. |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
calls("wangle", string("John"))->perl # wangle("John") |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
callm(scal("sub_ref"), string("John"))->perl # &{$sub_ref}("John") |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=cut |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
sub calls |
|
296
|
|
|
|
|
|
|
{ |
|
297
|
2
|
|
|
2
|
0
|
4
|
my $subname = shift; |
|
298
|
2
|
100
|
|
|
|
8
|
if (! ref($subname)) |
|
299
|
|
|
|
|
|
|
{ |
|
300
|
1
|
|
|
|
|
5
|
$subname = subname($subname); |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
|
|
303
|
2
|
|
|
|
|
6
|
return Code::Perl::Expr::CallSub->new( |
|
304
|
|
|
|
|
|
|
SubName => $subname, |
|
305
|
|
|
|
|
|
|
Args => list(@_) |
|
306
|
|
|
|
|
|
|
); |
|
307
|
|
|
|
|
|
|
} |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head2 CallMethod |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
$class->new(Object => $object, MethodName => $method, Args => $args); |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
callm($object, $methodname, @args); |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$object, $method, $args - Expression object. |
|
316
|
|
|
|
|
|
|
$methodname - an Expression object or a string |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
C will turn $methodname into a SubName object if it is a string. It |
|
319
|
|
|
|
|
|
|
will wrap @args in a List object. |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
CallMethod will produce code to call the method in $method on the object in |
|
322
|
|
|
|
|
|
|
$object, passing the list in $args. |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
callm(scal("obj"), "setName", string("John"))->perl # $obj->setName("John") |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
callm(scal("obj"), scal("meth"), string("John"))->perl # $obj->$meth("John") |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
It is possible to pass in any Expression object in $method, however the only |
|
329
|
|
|
|
|
|
|
ones that make sense are SubName and Scalar objects. |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=cut |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
sub callm |
|
334
|
|
|
|
|
|
|
{ |
|
335
|
2
|
|
|
2
|
0
|
5
|
my $object = shift; |
|
336
|
2
|
|
|
|
|
3
|
my $method = shift; |
|
337
|
2
|
100
|
|
|
|
7
|
if (! ref($method)) |
|
338
|
|
|
|
|
|
|
{ |
|
339
|
1
|
|
|
|
|
3
|
$method = subname($method); |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
2
|
|
|
|
|
6
|
return Code::Perl::Expr::CallMethod->new( |
|
343
|
|
|
|
|
|
|
Object => $object, |
|
344
|
|
|
|
|
|
|
MethodName => $method, |
|
345
|
|
|
|
|
|
|
Args => list(@_) |
|
346
|
|
|
|
|
|
|
); |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=head2 Perl |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
$class->new(Perl => $perl); |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
perl($perl); |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
$perl - a string of Perl code. |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
Perl allows you to insert a piece of Perl code |
|
358
|
|
|
|
|
|
|
as is, without have to parse it and turn it into a Code::Perl structure. |
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
perl("2 + 2")->perl # 2 + 2 |
|
361
|
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=cut |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
sub perl |
|
365
|
|
|
|
|
|
|
{ |
|
366
|
2
|
|
|
2
|
0
|
219
|
return Code::Perl::Expr::Perl->new( |
|
367
|
|
|
|
|
|
|
Perl => shift, |
|
368
|
|
|
|
|
|
|
); |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=head2 Holder |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
$class->new(Expr => $expr); |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
holder($expr); |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
$expr - an Expression object. |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
A Holder simply holds another |
|
380
|
|
|
|
|
|
|
expression inside. A Holder is useful when you want "parameterise" an |
|
381
|
|
|
|
|
|
|
expression. For example, |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
$holder = holder(); |
|
384
|
|
|
|
|
|
|
$exp = derefh(scal("hash"), derefa(scal("array", $holder)); |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
$holder->setExpr(number(10)); |
|
387
|
|
|
|
|
|
|
print $exp->perl # $hash->{$array->[10]); |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
$holder->setExpr(calls("getnum")); |
|
390
|
|
|
|
|
|
|
print $exp->perl # $hash->{$array->[getnum()]); |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
A single Holder can be placed in more than one position in your tree, |
|
393
|
|
|
|
|
|
|
allowing you make the same expression appear in multiple places in your code |
|
394
|
|
|
|
|
|
|
of you code and allowing you to change all of the occurrences at the same |
|
395
|
|
|
|
|
|
|
time. |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
=cut |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub holder |
|
400
|
|
|
|
|
|
|
{ |
|
401
|
1
|
|
|
1
|
0
|
10
|
return Code::Perl::Expr::Holder->new( |
|
402
|
|
|
|
|
|
|
Expr => shift, |
|
403
|
|
|
|
|
|
|
); |
|
404
|
|
|
|
|
|
|
} |
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
1; |
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
__END__ |