Perl::Stripper(3)

πŸ“¦
version 0.10 Β· 2 versions
, in fedora 43

πŸ’– Perl::Stripper πŸ’–

okay bestie, welcome to the manual page for Perl::Stripper(3) β€” yet another PPI-based Perl source code stripper 🧚✨ she's a User Contributed Perl Documentation girlie and she is HERE to help you peel the juicy info out of your source code 🌸


✨ VERSION ✨

This doc describes version 0.10 of Perl::Stripper (from the Perl distribution Perl-Stripper), released on 2017-07-11. yes it's a whole vibe, it's been around πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

use Perl::Stripper;

my $stripper = Perl::Stripper->new(
    #maintain_linum => 1, # the default, keep line numbers unchanged
    #strip_ws       => 1, # the default, strip extra whitespace
    #strip_comment  => 1, # the default
    #strip_pod      => 1, # the default
    strip_log       => 1, # default is 0, strip Log::Any log statements
);
$stripped = $stripper->strip($perl);

periodt. that's the whole flow 🫢


🌈 DESCRIPTION 🌈

So. This module is yet another PPI-based Perl source code stripper. Her whole thing β€” her main character energy, if you will β€” is costumization and stripping meaningful information out of source code. That's the mission. That's the assignment. And she ate. πŸ’…


πŸŽ€ ATTRIBUTES πŸŽ€

πŸ’œ maintain_linum => BOOL (default: 1)

Set this to true and the stripper will try to keep line numbers the same between the unstripped version and the stripped version. no cap, this is genuinely useful for debugging πŸ”₯

Respected by other settings. so like, she's the popular girl and all the other options listen to her.

πŸ’œ strip_ws => BOOL (default: 1)

Strip extra whitespace β€” indentation, padding, even non-significant newlines. Under maintain_linum, she will not strip newlines. gotta respect the line numbers bestie ✨

Not yet implemented. 😭 so don't come for her, it's coming, it's just not here yet.

πŸ’œ strip_comment => BOOL (default: 1) | CODE

If true, will strip comments. Under maintain_linum she replaces comment lines with blank lines instead.

The shebang line (like #!/usr/bin/perl, sitting at the beginning of a script) will not be stripped. she's protected, she's the chosen one πŸ‘‘

You can also set this to a coderef! Your code gets handed the PPI comment token object and is expected to modify that object (e.g. using the set_content() method). More deets in PPI::Token::Comment. Some usage ideas: translate a comment, replace a comment with gibberish, etc. go off πŸ’…

πŸ’œ strip_log => BOOL (default: 1)

If true, will strip log statements. super useful for ripping out debugging information. Currently supports Log::Any and Log::ger, and only looks for these statements:

$log->LEVEL(...);
$log->LEVELf(...);
log_LEVEL(...);
if ($log->is_LEVEL) { ... }
if (log_is_LEVEL()) { ... }

Not all methods are stripped. check out stripped_log_levels for the tea.

You can also set this to a coderef. Your code gets given the PPI::Statement object and is expected to modify it.

And these ones? Currently NOT stripped, sorry:

if (something && $log->is_LEVEL) { ... }

πŸ’œ stripped_log_levels => ARRAY_OF_STR (default: ['debug', 'trace'])

Which log levels get stripped. By default only debug and trace get the boot. Levels info and up are considered important for users (as opposed to for developers only), so they stay 🌸

πŸ’œ strip_pod => BOOL (default: 1)

If true, will strip POD. Under maintain_linum she replaces POD with blank lines.

You can also set this to a coderef! Your code gets the PPI POD token object and is expected to modify it (e.g. using the set_content() method). See PPI::Token::Pod for more details. Some usage ideas: translate POD, convert POD to Markdown, replace POD with gibberish, etc. the possibilities are literally endless πŸ’–


🫢 METHODS 🫢

⭐ new(%attrs) => OBJ

Constructor. that's it, that's the girl.

⭐ $stripper->strip($perl) => STR

Strip Perl source code. Returns the stripped source code. slay ✨


πŸ™ˆ FAQ πŸ™ˆ

πŸ’€ What is the use of this module?

Okay so! This module can be used to remove debugging information (logging statements, conditional code) from source code.

She can also be employed as part of a source code protection strategy. In theory you cannot hide source code you deploy to users/clients β€” but you can reduce how useful that deployed source code is by removing information like comments and POD (documentation), or by mangling subroutine/variable names (removing meaningful original subroutine/variable names). it's giving ✨mystery✨

And if what you actually want is compressing source code (reducing source code size), you can try Perl::Squish or Perl::Strip instead. different girlies for different needs πŸŽ€

πŸ’€ But isn't hiding/protecting source code immoral/unethical/ungrateful?

Bestie. Discussing hiding/protecting source code in general is really beyond the scope of this module's documentation. Please consult elsewhere. πŸ™ˆ

πŸ’€ How about obfuscating by encoding Perl code?

For example, changing:

foo();
bar();

into:

$src = base64_decode(...); # optionally multiple rounds
eval $src;

This doesn't really remove meaningful parts of a source code, so the author is not very interested in this approach. You can send a patch if you want. πŸ’…

πŸ’€ How about changing string into hexadecimal characters? How about ...?

Other examples similar in spirit would be adding extra parentheses to expressions, or changing constant numbers into mathematical expressions.

Again β€” this does not remove meaningful parts of a source code (instead, they just transform stuffs). The effect can be reversed trivially using Perl::Tidy or B::Deparse. So, not very interested, but you can send a patch if you want. πŸ¦‹


🌸 HOMEPAGE 🌸

Please visit the project's homepage at <https://metacpan.org/release/Perl-Stripper>. go give her a follow πŸ’–


🌸 SOURCE 🌸

Source repository is at <https://github.com/perlancar/perl-Perl-Stripper>. it's right there, bestie πŸ‘‘


πŸŽ€ BUGS πŸŽ€

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Stripper>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. fr fr, it helps so much 😭


πŸ”₯ SEE ALSO πŸ”₯

There are at least two approaches when analyzing/modifying/producing Perl code: B-based and PPI-based. In general, B-based modules are orders of magnitude faster than PPI-based ones, but each approach has its strengths and weaknesses. iykyk πŸ’…

  • B::Deparse β€” strips comments and extra newlines
  • B::Deobfuscate β€” like B::Deparse, but can also rename variables. Despite its name, if applied to a "normal" Perl code, the effect is obfuscation, because it removes the original names (and meaning) of variables. the way that's so ironic 😭
  • Perl::Strip β€” PPI-based, focus on compression.
  • Perl::Squish β€” PPI-based, focus on compression.

πŸ’– AUTHOR πŸ’–

perlancar <perlancar@cpan.org>


This software is copyright (c) 2017, 2015, 2014, 2013, 2012 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 🫢


and that's a wrap, bestie πŸŽ€ this page came to you from perl v5.42.0, dated 2025-07-25, and it's the manual for Perl::Stripper(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from