lib/PAR/Filter/PatchContent.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 3 SCAR 13.3
CC
3
Cov
0%
PATCH_CONTENT
6.0
apply
6.0
BEGIN
2.0
CRAP 3.8
1 package PAR::Filter::PatchContent;
2 use 5.006;
3 use strict;
4 use warnings;
5 use base 'PAR::Filter';
6  
7 =head1 NAME
8  
9 PAR::Filter::PatchContent - Content patcher
10  
11 =head1 SYNOPSIS
12  
13 # transforms $code
14 PAR::Filter::PatchContent->apply(\$code, $filename, $name);
15  
16 =head1 DESCRIPTION
17  
18 This filter fixes PAR-incompatible modules; F<pp> applies it to modules
19 by default.
20  
21 =cut
22  
23 sub PATCH_CONTENT () { +{
24 map { ref($_) ? $_ : lc($_) }
25 'AutoLoader.pm' => [
26 '$is_dosish = ' =>
27 '$is_dosish = $^O eq \'cygwin\' || ',
28 ],
29 'DynaLoader.pm' => [
30 'my $do_expand = ' => # perl >= 5.36.0
31 'use vars qw($do_expand); $do_expand = ',
32 ],
33 'Pod/Usage.pm' => [
34 ' = $0' =>
35 ' = $ENV{PAR_0} || $0',
36 ],
37 # Some versions of Spreadsheet::ParseExcel have a weird non-POD construct =cmmt
38 # that is used to comment out a block of code. perl treats it as POD and strips it.
39 # Since it's not POD, POD parsers ignore it.
40 # PAR::Filter::PodStrip only strips valid POD. Hence we remove it here.
41 'Spreadsheet/ParseExcel.pm' => [
42 qr/^=cmmt\s+.*?^=cut\s*/sm =>
43 '',
44 ],
45 'SQL/Parser.pm' => [
46 'my @dialects;' =>
47 'require PAR;
48 my @dialects = ();
49 foreach my $member ( $PAR::LastAccessedPAR->members ) {
50 next unless $member->fileName =~ m!\bSQL/Dialects/([^/]+)\.pm$!;
51 push @dialects, $1;
52 }
53 ',
54 ],
55 'Tk.pm' => [
56 'foreach $dir (@INC)' =>
57 'require PAR;
58 if (my $member = PAR::unpar($0, $file, 1)) {
59 $file =~ s![/\\\\]!_!g;
60 return PAR::Heavy::_dl_extract($member,$file,$file);
61 }
62 if (my $member = PAR::unpar($0, my $name = $_[1], 1)) {
63 $name =~ s![/\\\\]!_!g;
64 return PAR::Heavy::_dl_extract($member,$name,$name);
65 }
66 foreach $dir (@INC)',
67 ],
68 'Tk/Widget.pm' => [
69 'if (defined($name=$INC{"$pkg.pm"}))' =>
70 'if (defined($name=$INC{"$pkg.pm"}) and !ref($name) and $name !~ m!^/loader/!)',
71 ],
72 'Win32/API/Type.pm' => [
73 'INIT ' => '',
74 ],
75 'Win32/SystemInfo.pm' => [
76 '$dll .= "cpuspd.dll";' =>
77 'require PAR;
78 $dll = "lib/Win32/cpuspd.dll";
79 if (my $member = PAR::unpar($0, $dll, 1)) {
80 $dll = PAR::Heavy::_dl_extract($member,"cpuspd.dll","cpuspd.dll");
81 $dll =~ s!\\\\!/!g;
82 } else { die $! }',
83 ],
84 'XSLoader.pm' => [
85 'goto retry unless $module and defined &dl_load_file;' =>
86 'goto retry;', # XSLoader <= 0.10
87 'goto \&XSLoader::bootstrap_inherit unless $module and defined &dl_load_file;' =>
88 'goto \&XSLoader::bootstrap_inherit;', # XSLoader >= 0.14
89 ],
90 'diagnostics.pm' => [
91 'CONFIG: ' => 'CONFIG: if (0) ',
92 'if (eof(POD_DIAG)) ' => 'if (0 and eof(POD_DIAG)) ',
93 'close POD_DIAG' => '# close POD_DIAG',
94 'while (<POD_DIAG>) ' =>
95 'require PAR; use Config;
96 my @files = (
97 "lib/pod/perldiag.pod",
98 "lib/Pod/perldiag.pod",
99 "lib/pod/perldiag-$Config{version}.pod",
100 "lib/Pod/perldiag-$Config{version}.pod",
101 "lib/pods/perldiag.pod",
102 "lib/pods/perldiag-$Config{version}.pod",
103 );
104 my $contents;
105 foreach my $file (@files) {
106 $contents = PAR::read_file($file);
107 last if defined $contents;
108 }
109 for(map "$_\\n\\n", split/(?:\\r?\\n){2,}/, $contents) ',
110 ],
111 'utf8_heavy.pl' => [
112 '$list ||= eval { $caller->$type(); }'
113 => '$list = eval { $caller->$type(); }',
114 '|| croak("Can\'t find $encoding character property definition via $caller->$type or $file.pl")'
115 => '|| croak("Can\'t find $encoding character property definition via $caller->$type or $file.pl") unless $list;'
116 ],
117 } };
118  
119 sub apply {
120 my ($class, $ref, $filename, $name) = @_;
121 { use bytes; $$ref =~ s/^\xEF\xBB\xBF//; } # remove utf8 BOM
122  
123 my @rule = @{PATCH_CONTENT->{lc($name)}||[]} or return $$ref;
124 while (my ($from, $to) = splice(@rule, 0, 2)) {
125 if (ref($from) eq 'Regexp') {
126 $$ref =~ s/$from/$to/g;
127 }
128 else {
129 $$ref =~ s/\Q$from\E/$to/g;
130 }
131 }
132 return $$ref;
133 }
134  
135 1;
136  
137 =head1 SEE ALSO
138  
139 L<PAR::Filter>
140  
141 =head1 AUTHORS
142  
143 Audrey Tang E<lt>cpan@audreyt.orgE<gt>
144  
145 You can write
146 to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty mail to
147 E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
148 Archives of the mailing list are available at
149 E<lt>https://www.mail-archive.com/par@perl.org/E<gt> or E<lt>https://groups.google.com/g/perl.parE<gt>.
150  
151 Please submit bug reports to E<lt>https://github.com/rschupp/PAR-Packer/issuesE<gt>.
152  
153 =head1 COPYRIGHT
154  
155 Copyright 2003-2009 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>.
156  
157 This program is free software; you can redistribute it and/or modify it
158 under the same terms as Perl itself.
159  
160 See F<LICENSE>.
161  
162 =cut