NAME

App::SlimPacker - PPI-based minifier and fatpack-style bundler for standalone Perl scripts

VERSION

Version 0.02

SYNOPSIS

use App::SlimPacker qw(process module_deps inline_plugins);

# Minify Perl source (strip comments/POD, collapse whitespace, rename vars)
my $minified = process($source, rename => 1);

# Extract static dependencies from source
my @deps = module_deps('use App::Foo; require App::Bar;');

# Inline Module::Pluggable plugin list
my $boot = inline_plugins($program, \%classes);

DESCRIPTION

App::SlimPacker provides a PPI-based minifier and bundling helpers for building standalone Perl scripts. It is used by the slimpack CLI to assemble fatpacked, minified executables.

The minifier (process) strips comments and POD, collapses whitespace, and optionally renames my variables to short names while respecting string interpolation, regexes, heredocs, and readlines. local/our declarations are left untouched because they may be package globals reachable by a fully-qualified $PKG::name reference elsewhere.

The bundling helpers resolve static dependencies, inline Module::Pluggable plugin lists, and build perl-style switch programs from -m/-M/-e/-E arguments.

Unlike fatpack, which copies bundled modules verbatim, the slimpack pipeline runs every module through the PPI minifier. Packing this Moo hello-world into a self-contained script:

package MyGreeter;
use Moo;
has name => (is => 'ro', default => sub { 'world' });
sub greet { my $self = shift; return "Hello, " . $self->name . "!\n"; }
package main;
print MyGreeter->new->greet;

with Moo on the module path:

fatpack pack helloworld.pl > helloworld.fatpack.pl
slimpack -o helloworld.slimpack.pl helloworld.pl

fatpack produced 294 KB across 9,929 lines, slimpack 59 KB across 27 lines; both print Hello, world! with no Moo and no PERL5LIB at run time. Sizes vary with the module set.

EXPORTS

Nothing is exported by default. All functions are available for import:

use App::SlimPacker qw(process module_deps);

FUNCTIONS

process($source, %options)

Minifies Perl source code using PPI. Returns the minified string.

Options:

rename => 0|1

Rename my variables to short names (a, b, ... aa, ...). Enabled by default. Set to 0 to keep variable names intact (useful for fatlib core modules).

Variable renaming skips names used inside strings, regexes, heredocs, readlines, backticks, %KEEP names, ALL_CAPS names, and single-character names.

module_deps($source)

Returns a list of module names statically declared as dependencies in the given Perl source. Extracts modules from use, require, use base, use parent, and string-form require "Foo/Bar.pm". Pragmas (strict, warnings, lib, etc.) are skipped.

plugin_search_paths($program)

Extracts Module::Pluggable search paths from a program's use Module::Pluggable (...) statement. Returns a hashref of namespace => 1.

inline_plugins($program, \%classes)

Inlines a plugin class list into plugins() calls based on the Module::Pluggable search paths in $program and the available classes (hashref of Class::Name => 1). Classes are matched one level deep (Module::Pluggable's default), sorted. The use Module::Pluggable statement is removed so it never loads at runtime.

Returns the modified program text. Programs without Module::Pluggable or without a search_path are returned unchanged.

perl_switches(\@m, \@M, \@e, \@E)

Builds a Perl program string from -m/-M/-e/-E switch arguments (perl-binary style). Returns the program text with appropriate use statements prepended.

name_gen($n)

Returns a short variable name for the index $n: 0 -> a, 1 -> b, 25 -> z, 26 -> aa, etc.

needs_space($left_token, $right_token)

Returns 1 if a space is needed between two PPI tokens to prevent them from merging into a single token, 0 otherwise.

AUTHOR

Nicolas Mendoza, <mendoza at pvv.ntnu.no>

LICENSE AND COPYRIGHT

This software is licensed under the Artistic License 2.0. See the LICENSE file in this distribution for the full text.

SEE ALSO

slimpack, PPI, App::FatPacker