lib/PAR/Filter/PatchContent.pm untested

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