lib/PAR/Filter/Bytecode.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.5
CC
2
Cov
0%
apply
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package PAR::Filter::Bytecode;
2 use 5.006;
3 use strict;
4 use warnings;
5 use base 'PAR::Filter';
6 use File::Temp ();
7  
8 =head1 NAME
9  
10 PAR::Filter::Bytecode - Bytecode filter
11  
12 =head1 SYNOPSIS
13  
14 PAR::Filter::Bytecode->apply(\$code); # transforms $code
15  
16 =head1 DESCRIPTION
17  
18 B<This filter is deprecated. The B::Bytecode code has been removed from
19 the newest development series of perl and will not be included in perl
20 5.10 any more. Please have a look at Steve Hay's L<PAR::Filter::Crypto>
21 module if you want to hide your sources.>
22  
23 This filter uses L<B::Bytecode> to turn the script into comment-free,
24 architecture-specific Perl bytecode, and uses L<ByteLoader> to load
25 back on execution.
26  
27 For L<pp> users, please add an extra B<-M> option, like this:
28  
29 pp -f Bytecode -M ByteLoader
30  
31 Otherwise, the implicit dependency on ByteLoader will not be detected.
32  
33 =head1 CAVEATS
34  
35 This backend exhibits all bugs listed in L<B::Bytecode>, and then some.
36  
37 Bytecode support is considered to be extremely fragile on Perl versions
38 earlier than 5.8.1, and is still far from robust (as of this writing).
39  
40 Bytecode is not supported by perl 5.9 and later.
41  
42 =cut
43  
44 sub apply {
45 my $ref = $_[1];
46  
47 my ($fh, $in_file) = File::Temp::tempfile();
48 print $fh $$ref;
49 close $fh;
50  
51 my $out_file = File::Temp::tmpnam();
52 system($^X, "-MO=Bytecode,-H,-k,-o$out_file", $in_file);
53 unless (-e $out_file) {
54 warn "Cannot transform $in_file to $out_file: $! ($?)\n";
55 return;
56 }
57  
58 unlink($in_file);
59  
60 open my $fh, '<', $out_file or die $!;
61 local $/;
62 $$ref = <$fh>;
63 close $fh;
64  
65 unlink($out_file);
66 }
67  
68 1;
69  
70 =head1 SEE ALSO
71  
72 L<PAR::Filter>, L<B::Bytecode>, L<ByteLoader>
73  
74 L<Filter::Crypto>, L<PAR::Filter::Crypto>
75  
76 =head1 AUTHORS
77  
78 Audrey Tang E<lt>cpan@audreyt.orgE<gt>
79  
80 You can write
81 to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty mail to
82 E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
83 Archives of the mailing list are available at
84 E<lt>https://www.mail-archive.com/par@perl.org/E<gt> or E<lt>https://groups.google.com/g/perl.parE<gt>.
85  
86 Please submit bug reports to E<lt>https://github.com/rschupp/PAR-Packer/issuesE<gt>.
87  
88 =head1 COPYRIGHT
89  
90 Copyright 2003-2009 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>.
91  
92 This program is free software; you can redistribute it and/or modify it
93 under the same terms as Perl itself.
94  
95 See F<LICENSE>.
96  
97 =cut