| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::RecordStream::DomainLanguage::Snippet; |
|
2
|
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
166
|
use strict; |
|
|
27
|
|
|
|
|
51
|
|
|
|
27
|
|
|
|
|
677
|
|
|
4
|
27
|
|
|
27
|
|
115
|
use warnings; |
|
|
27
|
|
|
|
|
61
|
|
|
|
27
|
|
|
|
|
574
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
27
|
|
|
27
|
|
9676
|
use App::RecordStream::DomainLanguage::Executor; |
|
|
27
|
|
|
|
|
87
|
|
|
|
27
|
|
|
|
|
815
|
|
|
7
|
27
|
|
|
27
|
|
151
|
use App::RecordStream::DomainLanguage::Value; |
|
|
27
|
|
|
|
|
54
|
|
|
|
27
|
|
|
|
|
532
|
|
|
8
|
27
|
|
|
27
|
|
116
|
use App::RecordStream::Executor; |
|
|
27
|
|
|
|
|
50
|
|
|
|
27
|
|
|
|
|
14907
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
438
|
|
|
438
|
0
|
45366
|
my $class = shift; |
|
13
|
438
|
|
|
|
|
653
|
my $code = shift; |
|
14
|
438
|
|
|
|
|
579
|
my $vars = shift; |
|
15
|
|
|
|
|
|
|
|
|
16
|
438
|
|
|
|
|
1144
|
$code = App::RecordStream::Executor->transform_code($code); |
|
17
|
438
|
|
|
|
|
886
|
$code = _transform_angles($code); |
|
18
|
|
|
|
|
|
|
|
|
19
|
438
|
|
|
|
|
1172
|
my $this = |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
|
|
|
|
|
|
'CODE' => $code, |
|
22
|
|
|
|
|
|
|
'VARS' => $vars, |
|
23
|
|
|
|
|
|
|
}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
438
|
|
|
|
|
724
|
bless $this, $class; |
|
26
|
|
|
|
|
|
|
|
|
27
|
438
|
|
|
|
|
1312
|
return $this; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub evaluate_as |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
389
|
|
|
389
|
0
|
32530
|
my $this = shift; |
|
33
|
389
|
|
|
|
|
545
|
my $type = shift; |
|
34
|
389
|
|
100
|
|
|
1069
|
my $vars = shift || {}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
389
|
|
|
|
|
1167
|
my $executor = App::RecordStream::DomainLanguage::Executor->new(); |
|
37
|
389
|
|
|
|
|
983
|
$executor->import_registry(); |
|
38
|
|
|
|
|
|
|
|
|
39
|
389
|
|
|
|
|
692
|
for my $var (%{$this->{'VARS'}}) |
|
|
389
|
|
|
|
|
1081
|
|
|
40
|
|
|
|
|
|
|
{ |
|
41
|
42
|
|
|
|
|
60
|
for my $ref (@{$this->{'VARS'}->{$var}}) |
|
|
42
|
|
|
|
|
92
|
|
|
42
|
|
|
|
|
|
|
{ |
|
43
|
36
|
|
|
|
|
74
|
$executor->set_ref($var, $ref); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
389
|
|
|
|
|
938
|
for my $var (keys(%$vars)) |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
302
|
50
|
|
|
|
1335
|
if(0) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
} |
|
52
|
0
|
|
|
|
|
0
|
elsif($var =~ /^\$(.*)$/) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
302
|
|
|
|
|
881
|
$executor->set_scalar($1, $vars->{$var}); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
else |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
0
|
|
|
|
|
0
|
die "Bad var for snippet: '$var'"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
389
|
|
|
|
|
1044
|
my $result = $executor->exec($this->{'CODE'}); |
|
62
|
|
|
|
|
|
|
|
|
63
|
389
|
|
|
|
|
1037
|
return App::RecordStream::DomainLanguage::Value::cast_or_die($type, $result); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _transform_angles |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
438
|
|
|
438
|
|
667
|
my $code = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
438
|
|
|
|
|
557
|
my $pos = 0; |
|
71
|
438
|
|
|
|
|
614
|
my $out = ''; |
|
72
|
438
|
|
|
|
|
503
|
while(1) |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
484
|
|
|
|
|
835
|
my $top_level_entrance = index($code, '<<', $pos); |
|
75
|
484
|
100
|
|
|
|
834
|
if($top_level_entrance == -1) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
438
|
|
|
|
|
898
|
$out .= substr($code, $pos); |
|
78
|
438
|
|
|
|
|
677
|
last; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
46
|
|
|
|
|
109
|
my $level = 1; |
|
82
|
46
|
|
|
|
|
78
|
my $pos2 = $top_level_entrance + 2; |
|
83
|
46
|
|
|
|
|
78
|
my $top_level_exit; |
|
84
|
46
|
|
|
|
|
66
|
while(1) |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
46
|
|
|
|
|
98
|
my $next_enter = index($code, '<<', $pos2); |
|
87
|
46
|
|
|
|
|
100
|
my $next_exit = index($code, '>>', $pos2); |
|
88
|
|
|
|
|
|
|
|
|
89
|
46
|
50
|
33
|
|
|
171
|
if($next_enter != -1 && ($next_exit == -1 || $next_enter < $next_exit)) |
|
|
|
|
66
|
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
|
91
|
0
|
|
|
|
|
0
|
++$level; |
|
92
|
0
|
|
|
|
|
0
|
$pos2 = $next_enter + 2; |
|
93
|
0
|
|
|
|
|
0
|
next; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
46
|
50
|
66
|
|
|
192
|
if($next_exit != -1 && ($next_enter == -1 || $next_exit < $next_enter)) |
|
|
|
|
66
|
|
|
|
|
|
97
|
|
|
|
|
|
|
{ |
|
98
|
46
|
|
|
|
|
70
|
--$level; |
|
99
|
46
|
50
|
|
|
|
82
|
if($level == 0) |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
46
|
|
|
|
|
69
|
$top_level_exit = $next_exit; |
|
102
|
46
|
|
|
|
|
73
|
last; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
0
|
$pos2 = $next_enter + 2; |
|
105
|
0
|
|
|
|
|
0
|
next; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
die "Unbalanced << and >> in snippet: $code"; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
46
|
|
|
|
|
114
|
$out .= substr($code, $pos, $top_level_entrance - $pos); |
|
112
|
46
|
|
|
|
|
146
|
$out .= _quote_snippet(substr($code, $top_level_entrance + 2, $top_level_exit - $top_level_entrance - 2)); |
|
113
|
46
|
|
|
|
|
95
|
$pos = $top_level_exit + 2; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
438
|
|
|
|
|
728
|
return $out; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _quote_snippet |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
46
|
|
|
46
|
|
110
|
my $code = shift; |
|
122
|
|
|
|
|
|
|
|
|
123
|
46
|
|
|
|
|
65
|
my @vars; |
|
124
|
46
|
100
|
|
|
|
135
|
if($code =~ s/^([a-zA-Z_][a-zA-Z_0-9]*(,[a-zA-Z_][a-zA-Z_0-9]*)*)\|//) |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
4
|
|
|
|
|
11
|
@vars = split(/,/, $1); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Could not get typeglobs to work. References go in, references come out, |
|
130
|
|
|
|
|
|
|
# you can't explain that... |
|
131
|
46
|
|
|
|
|
202
|
return "snip(App::RecordStream::DomainLanguage::Snippet->new('$code', {" . join(", ", map { "'$_' => [\\\$$_, \\\@$_, \\\%$_]" } @vars) . "}))"; |
|
|
6
|
|
|
|
|
27
|
|
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |