line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tak::EvalService; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1609
|
use Eval::WithLexicals; |
|
1
|
|
|
|
|
3169
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
6
|
use Data::Dumper::Concise; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
5
|
1
|
|
|
1
|
|
7
|
use Capture::Tiny qw(capture); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Tak::Role::Service'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'eval_withlexicals' => (is => 'lazy'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'service_client' => (is => 'ro', predicate => 'has_service_client'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _build_eval_withlexicals { |
15
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
16
|
0
|
0
|
|
|
|
|
Eval::WithLexicals->new( |
17
|
|
|
|
|
|
|
$self->has_service_client |
18
|
|
|
|
|
|
|
? (lexicals => { '$client' => \($self->service_client) }) |
19
|
|
|
|
|
|
|
: () |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub handle_eval { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $perl) = @_; |
25
|
0
|
0
|
|
|
|
|
unless ($perl) { |
26
|
0
|
|
|
|
|
|
die [ mistake => eval_input => "No code supplied" ]; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
0
|
|
|
|
|
if (my $ref = ref($perl)) { |
29
|
0
|
|
|
|
|
|
die [ mistake => eval_input => "Code was a ${ref} reference" ]; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
my ($ok, @ret); |
32
|
0
|
|
|
|
|
|
my ($stdout, $stderr); |
33
|
0
|
0
|
|
|
|
|
if (eval { |
34
|
|
|
|
|
|
|
($stdout, $stderr) = capture { |
35
|
0
|
|
|
0
|
|
|
@ret = $self->eval_withlexicals->eval($perl); |
36
|
0
|
|
|
|
|
|
}; |
37
|
0
|
|
|
|
|
|
1 |
38
|
|
|
|
|
|
|
}) { |
39
|
0
|
|
|
|
|
|
$ok = 1; |
40
|
|
|
|
|
|
|
} else { |
41
|
0
|
|
|
|
|
|
($ok, @ret) = (0, $@); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
my $dumped_ret; |
44
|
0
|
0
|
|
|
|
|
unless (eval { $dumped_ret = Dumper(@ret); 1 }) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
$dumped_ret = "Error dumping ${\($ok ? 'result' : 'exception')}: $@"; |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$ok = 0; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
return { |
49
|
0
|
0
|
|
|
|
|
stdout => $stdout, stderr => $stderr, |
50
|
|
|
|
|
|
|
($ok ? 'return' : 'exception') => $dumped_ret |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |