line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Inline::Interp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
6
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1607
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub usage_config { |
9
|
0
|
|
|
0
|
0
|
0
|
my $key = shift; |
10
|
0
|
|
|
|
|
0
|
"'$key' is not a valid config option for Inline::Interp\n"; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
0
|
3867
|
sub validate { |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub build { |
17
|
1
|
|
|
1
|
0
|
15
|
my $o = shift; |
18
|
1
|
|
|
|
|
2
|
my $package = ref $o; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
3
|
my $code = $o->{API}{code}; |
21
|
1
|
|
|
|
|
2
|
my $pattern = $o->{ILSM}{PATTERN}; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
3
|
my $funcs = { |
24
|
|
|
|
|
|
|
'class' => $package, |
25
|
|
|
|
|
|
|
'code' => '', |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
46
|
eval "${package}::do_load(\$funcs, \$code);"; |
29
|
1
|
|
|
|
|
3
|
$code = $funcs->{code}; |
30
|
|
|
|
|
|
|
{ |
31
|
1
|
|
|
|
|
2
|
package Inline::Interp::Loader; |
32
|
1
|
|
|
0
|
|
42
|
eval $code; |
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
} |
34
|
1
|
50
|
|
|
|
4
|
croak "Build failed:\n$@" if $@; |
35
|
1
|
|
|
|
|
5
|
my $path = "$o->{API}{install_lib}/auto/$o->{API}{modpname}"; |
36
|
1
|
|
|
|
|
3
|
my $obj = $o->{API}{location}; |
37
|
1
|
50
|
|
|
|
26
|
$o->mkpath($path) unless -d $path; |
38
|
1
|
50
|
|
|
|
414
|
open FOO_OBJ, "> $obj" or croak "Can't open $obj for output\n$!"; |
39
|
1
|
|
|
|
|
8
|
print FOO_OBJ $code; |
40
|
1
|
|
|
|
|
42
|
close \*FOO_OBJ; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_func { |
44
|
1
|
|
|
1
|
1
|
3
|
my ($funcs, $name, $code) = @_; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
4
|
$code =~ s/\|/\\|/g; |
47
|
1
|
|
|
|
|
12
|
$funcs->{code} .= "sub $name { return Inline::Interp::run('$funcs->{class}', q|$code|, \$_[0]); }\n"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub load { |
51
|
2
|
|
|
2
|
1
|
5
|
my $o = shift; |
52
|
2
|
|
|
|
|
14
|
my $obj = $o->{API}{location}; |
53
|
2
|
50
|
|
|
|
105
|
open FOO_OBJ, "< $obj" or croak "Can't open $obj for output\n$!"; |
54
|
2
|
|
|
|
|
36
|
my $code = join '', ; |
55
|
2
|
|
|
|
|
21
|
close \*FOO_OBJ; |
56
|
2
|
|
|
1
|
|
150
|
eval "package $o->{API}{pkg};\n$code"; |
|
1
|
|
|
1
|
|
637
|
|
|
1
|
|
|
1
|
|
290
|
|
|
1
|
|
|
|
|
5
|
|
57
|
2
|
50
|
|
|
|
12
|
croak "Unable to load Foo module $obj:\n$@" if $@; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub info { |
61
|
0
|
|
|
0
|
0
|
0
|
my $o = shift; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub run { |
65
|
3
|
|
|
3
|
0
|
9
|
my ($class, $code, $data) = @_; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
5
|
my @data; |
68
|
|
|
|
|
|
|
my $input_callback; |
69
|
0
|
|
|
|
|
0
|
my $output_callback; |
70
|
3
|
|
|
|
|
5
|
my $echo = 1; |
71
|
|
|
|
|
|
|
|
72
|
3
|
50
|
|
|
|
13
|
if (ref $data eq 'HASH'){ |
|
|
0
|
|
|
|
|
|
73
|
3
|
50
|
|
|
|
5
|
@data = split(//, ${$data}{input}) if ${$data}{input}; |
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
14
|
|
74
|
3
|
|
50
|
|
|
26
|
$input_callback = ${$data}{input_callback} || 0; |
75
|
3
|
|
50
|
|
|
6
|
$output_callback = ${$data}{output_callback} || 0; |
76
|
3
|
|
50
|
|
|
5
|
$echo = ${$data}{echo} || 0; |
77
|
|
|
|
|
|
|
}elsif (defined $data){ |
78
|
0
|
|
|
|
|
0
|
@data = split(//, $data); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
15
|
my $io = { |
82
|
|
|
|
|
|
|
'echo' => $echo, |
83
|
|
|
|
|
|
|
'buffer' => '', |
84
|
|
|
|
|
|
|
'output_callback' => $output_callback, |
85
|
|
|
|
|
|
|
'input_callback' => $input_callback, |
86
|
|
|
|
|
|
|
'data' => \@data, |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
3
|
|
|
|
|
186
|
eval "&${class}::do_run(\$code, \$io);"; |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
35
|
return $io->{buffer}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub output_char { |
95
|
24
|
|
|
24
|
1
|
31
|
my ($io, $char) = @_; |
96
|
|
|
|
|
|
|
|
97
|
24
|
50
|
|
|
|
51
|
print $char if $io->{echo}; |
98
|
24
|
|
|
|
|
29
|
$io->{buffer} .= $char; |
99
|
24
|
50
|
|
|
|
117
|
&{$io->{output_callback}}($char) if $io->{output_callback}; |
|
0
|
|
|
|
|
0
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub input_char { |
103
|
0
|
|
|
0
|
1
|
0
|
my ($io) = @_; |
104
|
0
|
0
|
|
|
|
0
|
return ($io->{input_callback})?&{$io->{input_callback}}:shift @{$io->{data}}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |