Tak/EvalService.pm

filter: Statementstmt 41.0% 16 / 39 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 1 totaltotal 32.7% 20 / 61 SCAR 33.9
CC
8
Cov
30%
handle_eval
56.0
_build_eval_withlexicals
6.0
__ANON__
2.0
CRAP 29.8
« Tak/CommandService.pm ↑ Summary Tak/STDIOSetup.pm »
1 package Tak::EvalService;
2  
3 1 ▶use Eval::WithLexicals;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Capture::Tiny qw(capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 with 'Tak::Role::Service';
9  
10 1 has 'eval_withlexicals' => (is => 'lazy');
11  
12 1 has 'service_client' => (is => 'ro', predicate => 'has_service_client');
13  
14 sub _build_eval_withlexicals {
15 0 ▶ my ($self) = @_;
Subroutine _build_eval_withlexicals: not called CC=2 SCAR=17.9
16 0 ▶ Eval::WithLexicals->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_service_client ? : 0 0 0
17 $self->has_service_client
18 ? (lexicals => { '$client' => \($self->service_client) })
19 : ()
20 );
21 }
22  
23 sub handle_eval {
24 0 ▶ my ($self, $perl) = @_;
Subroutine handle_eval: not called CC=7 SCAR=40.3
Pod undocumented
25 0 ▶ unless ($perl) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($perl) 0 0 0
26 0 die [ mistake => eval_input => "No code supplied" ];
27 }
28 0 ▶ if (my $ref = ref($perl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $perl) 0 0 0
29 0 die [ mistake => eval_input => "Code was a ${ref} reference" ];
30 }
31 0 my ($ok, @ret);
32 0 my ($stdout, $stderr);
33 0 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { () = &capture(sub { @ret = $self->eval_withlexicals->eval($perl); } ); 1 } }) { } 0 0 0
34 ($stdout, $stderr) = capture {
35 0 ▶ @ret = $self->eval_withlexicals->eval($perl);
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 ▶ unless (eval { $dumped_ret = Dumper(@ret); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $dumped_ret = Dumper(@ret); 1 } }) 0 0 0
45 0 ▶ $dumped_ret = "Error dumping ${\($ok ? 'result' : 'exception')}: $@";
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
46 0 $ok = 0;
47 }
48 return {
49 0 ▶ stdout => $stdout, stderr => $stderr,
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
50 ($ok ? 'return' : 'exception') => $dumped_ret
51 };
52 }
53  
54 1 1;
« Tak/CommandService.pm ↑ Summary Tak/STDIOSetup.pm »