File Coverage

blib/lib/PAR/Filter/Squish.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package PAR::Filter::Squish;
2              
3 2     2   1171 use strict;
  2         3  
  2         78  
4 2     2   11 use vars qw/$VERSION/;
  2         4  
  2         99  
5             $VERSION = '0.03';
6              
7 2     2   897 use Perl::Squish;
  0            
  0            
8             use base 'PAR::Filter';
9              
10             =head1 NAME
11              
12             PAR::Filter::Squish - PAR filter for reducing code size
13              
14             =head1 SYNOPSIS
15              
16             # transforms $code
17             PAR::Filter::Squish->apply(\$code, $filename, $name);
18              
19             =head1 DESCRIPTION
20              
21             This filter uses L to reduce the size of a module
22             as much as possible.
23              
24             It does not preserve line numbers, comments or documentation.
25              
26             Do not expect miracles. Unless you include B of modules,
27             the major component of a binary produced by C will be
28             shared object files and the perl run-time.
29              
30             =head1 METHODS
31              
32             =head2 apply
33              
34             Class method which applies the filter to source code. Expects a reference
35             to the code string as first argument optionally followed by file and
36             module name. Those names are particularily accepted for compatibility to
37             other PAR filters.
38              
39             =cut
40              
41             sub apply {
42             my ($class, $ref, $filename, $name) = @_;
43              
44             return if $filename =~ /\.bs$/i;
45             no warnings 'uninitialized';
46              
47             my $data = '';
48             $data = $1 if $$ref =~ s/((?:^__DATA__\r?\n).*)//ms;
49              
50             my $doc = PPI::Document->new($ref);
51             my $trafo = Perl::Squish->new();
52             if (not defined $doc) {
53             warn __PACKAGE__ . ": Could not parse '$filename' using PPI!";
54             $$ref .= $data;
55             return;
56             }
57             $trafo->apply($doc);
58             if (not defined $doc) {
59             warn __PACKAGE__ . ": Could not apply transformation to '$filename'!";
60             $$ref .= $data;
61             return;
62             }
63              
64             $$ref = $doc->serialize();
65            
66             $$ref .= $data;
67             }
68              
69             1;
70              
71             =head1 SEE ALSO
72              
73             L
74              
75             L
76              
77             L
78              
79             =head1 AUTHORS
80              
81             Steffen Mueller Esmueller@cpan.orgE
82              
83             L is the official PAR website. You can write
84             to the mailing list at Epar@perl.orgE, or send an empty mail to
85             Epar-subscribe@perl.orgE to participate in the discussion.
86              
87             Please submit bug reports to Ebug-par-filter-squish@rt.cpan.orgE.
88              
89             =head1 COPYRIGHT
90              
91             Copyright 2006-2008 by Steffen Mueller Esmueller@cpan.orgE.
92              
93             This program is free software; you can redistribute it and/or modify it
94             under the same terms as Perl itself.
95              
96             See L
97              
98             =cut