File Coverage

blib/lib/ExtUtils/Scriptlet.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition 5 7 71.4
subroutine 4 4 100.0
pod 1 1 100.0
total 34 36 94.4


line stmt bran cond sub pod time code
1 1     1   15552 use strictures;
  1         1  
  1         6  
2              
3             package ExtUtils::Scriptlet;
4              
5             our $VERSION = '1.131970'; # TRIAL VERSION
6              
7             # ABSTRACT: run perl code in a new process without quoting it, on any OS
8              
9             #
10             # This file is part of ExtUtils-Scriptlet
11             #
12             #
13             # Christian Walde has dedicated the work to the Commons by waiving all of his
14             # or her rights to the work worldwide under copyright law and all related or
15             # neighboring legal rights he or she had in the work, to the extent allowable by
16             # law.
17             #
18             # Works under CC0 do not require attribution. When citing the work, you should
19             # not imply endorsement by the author.
20             #
21              
22 1     1   187 use Exporter 'import';
  1         3  
  1         28  
23 1     1   365 use autodie;
  1         11536  
  1         4  
24              
25             our @EXPORT_OK = qw( perl );
26              
27              
28             sub perl {
29 8     8 1 2380 my ( $code, %p ) = @_;
30              
31 8 100       40 die "No code given" if !$code;
32 7 100       32 die "\\r is not permitted in the code segment" if $code =~ /\r/;
33              
34 6   33     43 $p{perl} ||= $^X;
35 6   100     26 $p{encoding} ||= ":encoding(UTF-8)";
36 6   100     69 $p{$_} ||= "" for qw( args argv payload );
37              
38 6         56 open #
39             my $fh, #
40             "|- $p{encoding}", #
41             "$p{perl} $p{args} - $p{argv}"; #
42              
43             print $fh #
44             $code #
45             . "\n__END__\n" #
46 6         24493 . $p{payload}; #
47              
48 6         14 eval { close $fh };
  6         121  
49              
50 6         13331 return $?;
51             }
52              
53             1;
54              
55             __END__