1Perl::Stripper(3)     User Contributed Perl Documentation    Perl::Stripper(3)
2
3
4

NAME

6       Perl::Stripper - Yet another PPI-based Perl source code stripper
7

VERSION

9       This document describes version 0.10 of Perl::Stripper (from Perl
10       distribution Perl-Stripper), released on 2017-07-11.
11

SYNOPSIS

13        use Perl::Stripper;
14
15        my $stripper = Perl::Stripper->new(
16            #maintain_linum => 1, # the default, keep line numbers unchanged
17            #strip_ws       => 1, # the default, strip extra whitespace
18            #strip_comment  => 1, # the default
19            #strip_pod      => 1, # the default
20            strip_log       => 1, # default is 0, strip Log::Any log statements
21        );
22        $stripped = $stripper->strip($perl);
23

DESCRIPTION

25       This module is yet another PPI-based Perl source code stripper. Its
26       focus is on costumization and stripping meaningful information from
27       source code.
28

ATTRIBUTES

30   maintain_linum => BOOL (default: 1)
31       If set to true, stripper will try to maintain line numbers so they do
32       not change between the unstripped and the stripped version. This is
33       useful for debugging.
34
35       Respected by other settings.
36
37   strip_ws => BOOL (default: 1)
38       Strip extra whitespace, like indentation, padding, even non-significant
39       newlines. Under "maintain_linum", will not strip newlines.
40
41       Not yet implemented.
42
43   strip_comment => BOOL (default: 1) | CODE
44       If set to true, will strip comments. Under "maintain_linum" will
45       replace comment lines with blank lines.
46
47       Shebang line (e.g. "#!/usr/bin/perl", located at the beginning of
48       script) will not be stripped.
49
50       Can also be set to a coderef. Code will be given the PPI comment token
51       object and expected to modify the object (e.g. using "set_content()"
52       method). See PPI::Token::Comment for more details. Some usage ideas:
53       translate comment, replace comment with gibberish, etc.
54
55   strip_log => BOOL (default: 1)
56       If set to true, will strip log statements. Useful for removing
57       debugging information. Currently supports Log::Any and Log::ger and
58       only looks for the following statements:
59
60        $log->LEVEL(...);
61        $log->LEVELf(...);
62        log_LEVEL(...);
63        if ($log->is_LEVEL) { ... }
64        if (log_is_LEVEL()) { ... }
65
66       Not all methods are stripped. See "stripped_log_levels".
67
68       Can also be set to a coderef. Code will be given the PPI::Statement
69       object and expected to modify it.
70
71       These are currently not stripped:
72
73        if (something && $log->is_LEVEL) { ... }
74
75   stripped_log_levels => ARRAY_OF_STR (default: ['debug', 'trace'])
76       Log levels to strip. By default, only "debug" and "trace" are stripped.
77       Levels "info" and up are considered important for users (instead of for
78       developers only).
79
80   strip_pod => BOOL (default: 1)
81       If set to true, will strip POD. Under "maintain_linum" will replace POD
82       with blank lines.
83
84       Can also be set to a coderef. Code will be given the PPI POD token
85       object and expected to modify the object (e.g. using "set_content()"
86       method). See PPI::Token::Pod for more details.Some usage ideas:
87       translate POD, convert POD to Markdown, replace POD with gibberish,
88       etc.
89

METHODS

91   new(%attrs) => OBJ
92       Constructor.
93
94   $stripper->strip($perl) => STR
95       Strip Perl source code. Return the stripped source code.
96

FAQ

98   What is the use of this module?
99       This module can be used to remove debugging information (logging
100       statements, conditional code) from source code.
101
102       This module can also be employed as part of source code protection
103       strategy. In theory you cannot hide source code you deploy to
104       users/clients, but you can reduce the usefulness of the deployed source
105       code by removing information such as comments and POD (documentation),
106       or by mangling subroutine/variable names (removing meaningful original
107       subroutine/variable names).
108
109       For compressing source code (reducing source code size), you can try
110       Perl::Squish or Perl::Strip.
111
112   But isn't hiding/protecting source code immoral/unethical/ungrateful?
113       Discussing hiding/protecting source code in general is really beyond
114       the scope of this module's documentation. Please consult elsewhere.
115
116   How about obfuscating by encoding Perl code?
117       For example, changing:
118
119        foo();
120        bar();
121
122       into:
123
124        $src = base64_decode(...); # optionally multiple rounds
125        eval $src;
126
127       This does not really remove meaningful parts of a source code, so I am
128       not very interested in this approach. You can send a patch if you want.
129
130   How about changing string into hexadecimal characters? How about ...?
131       Other examples similar in spirit would be adding extra parentheses to
132       expressions, changing constant numbers into mathematical expressions.
133
134       Again, this does not remove meaningful parts of a source code (instead,
135       they just transform stuffs). The effect can be reversed trivially using
136       Perl::Tidy or B::Deparse. So I am not very interested in doing this,
137       but you can send a patch if you want.
138

HOMEPAGE

140       Please visit the project's homepage at
141       <https://metacpan.org/release/Perl-Stripper>.
142

SOURCE

144       Source repository is at
145       <https://github.com/perlancar/perl-Perl-Stripper>.
146

BUGS

148       Please report any bugs or feature requests on the bugtracker website
149       <https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Stripper>
150
151       When submitting a bug or request, please include a test-file or a patch
152       to an existing test-file that illustrates the bug or desired feature.
153

SEE ALSO

155       There are at least two approaches when analyzing/modifying/producing
156       Perl code: B-based and PPI-based. In general, B-based modules are
157       orders of magnitude faster than PPI-based ones, but each approach has
158       its strengths and weaknesses.
159
160       B::Deparse - strips comments and extra newlines
161
162       B::Deobfuscate - like B::Deparse, but can also rename variables.
163       Despite its name, if applied to a "normal" Perl code, the effect is
164       obfuscation because it removes the original names (and meaning) of
165       variables.
166
167       Perl::Strip - PPI-based, focus on compression.
168
169       Perl::Squish - PPI-based, focus on compression.
170

AUTHOR

172       perlancar <perlancar@cpan.org>
173
175       This software is copyright (c) 2017, 2015, 2014, 2013, 2012 by
176       perlancar@cpan.org.
177
178       This is free software; you can redistribute it and/or modify it under
179       the same terms as the Perl 5 programming language system itself.
180
181
182
183perl v5.32.0                      2020-07-28                 Perl::Stripper(3)
Impressum