File Coverage

lib/FFI/Probe/Runner.pm
Criterion Covered Total %
statement 37 44 84.0
branch 3 6 50.0
condition 2 6 33.3
subroutine 12 12 100.0
pod 5 5 100.0
total 59 73 80.8


line stmt bran cond sub pod time code
1             package FFI::Probe::Runner;
2              
3 4     4   235272 use strict;
  4         7  
  4         136  
4 4     4   21 use warnings;
  4         10  
  4         166  
5 4     4   64 use 5.008004;
  4         12  
6 4     4   1477 use Capture::Tiny qw( capture );
  4         80981  
  4         349  
7 4     4   4230 use FFI::Probe::Runner::Result;
  4         56  
  4         2016  
8              
9             # ABSTRACT: Probe runner for FFI
10             our $VERSION = '2.11'; # VERSION
11              
12              
13             sub new
14             {
15 2     2 1 287420 my($class, %args) = @_;
16              
17 2   33     12 $args{exe} ||= do {
18 0         0 require FFI::Platypus::ShareConfig;
19 0         0 require File::Spec;
20 0         0 require Config;
21 0         0 File::Spec->catfile(FFI::Platypus::ShareConfig::dist_dir('FFI::Platypus'), 'probe', 'bin', "dlrun$Config::Config{exe_ext}");
22             };
23              
24 2 50       15 defined $args{flags} or $args{flags} = '-';
25              
26 2 50       57 die "probe runner executable not found at: $args{exe}" unless -f $args{exe};
27              
28             my $self = bless {
29             exe => $args{exe},
30             flags => $args{flags},
31 2         15 }, $class;
32 2         11 $self;
33             }
34              
35              
36 8     8 1 42 sub exe { shift->{exe} }
37 8     8 1 664 sub flags { shift->{flags} }
38              
39              
40             sub verify
41             {
42 1     1 1 2 my($self) = @_;
43 1         4 my $exe = $self->exe;
44             my($out, $err, $ret) = capture {
45 1     1   1775 $! = 0;
46 1         8663 system $exe, 'verify', 'self';
47 1         34 };
48 1 50 33     1778 return 1 if $ret == 0 && $out =~ /dlrun verify self ok/;
49 0         0 print $out;
50 0         0 print STDERR $err;
51 0         0 die "verify failed";
52             }
53              
54              
55             sub run
56             {
57 7     7 1 960 my($self, $dll, @args) = @_;
58 7         53 my $exe = $self->exe;
59 7         31 my $flags = $self->flags;
60             my($out, $err, $ret) = capture {
61 7     7   12222 my @cmd = ($exe, $dll, $flags, @args);
62 7         27 $! = 0;
63 7         46447 system @cmd;
64 7         672 $?;
65 7         697 };
66 7         9423 FFI::Probe::Runner::Result->new(
67             stdout => $out,
68             stderr => $err,
69             rv => $ret >> 8,
70             signal => $ret & 127,
71             );
72             }
73              
74             1;
75              
76             __END__