PPI::Normal(3)
💅 PPI::Normal — bestie we're normalizing ur Perl docs ✨
okay so real talk, this module lives in the PPI::Normal corner of the PPI world, and its whole job is making messy Perl look consistent. Let's get into it 🫶
✨ DESCRIPTION ✨
So here's the tea: Perl Documents, the ones PPI creates, are typically filled with all sorts of mess — whitespace, comments, and other little things that don't actually affect the real meaning of the code. Like, aesthetic clutter, not substance 💀
And on top of that? Because there's more than one way to do most things, and Perl's syntax is extremely flexible, there are like a million ways the "same" code can look completely different. It's giving chaos.
PPI::Normal is here to fix that. It gives you a whole variety of mechanisms and algorithms to "normalize" Perl Documents and figure out a sort of base form for them. Heads up though — that base form is a memory structure, and it's not something that can be turned back into Perl source code. It's a vibe, not a file, iykyk.
The process itself is genuinely complex, so for convenience and extensibility it's been separated into a bunch of layers. And at a later point, it'll be possible to write Plugin classes to insert additional normalization steps into the various different layers. ✨
Also! You can choose to do the normalization only as deep as a particular layer, depending on how aggressively you want the normalization process to go. Slay, customizable.
🛠 METHODS
register $function => $layer, ...
The register method is what normalization method providers use to tell the normalization engines which functions need to be run, and in which layer they apply. It's the group chat where everybody announces where they're sitting.
You provide a set of key/value pairs, where:
- the key is the full name of the function (in string form)
- the value is the layer (see the description of the layers above) in which it should be run
Returns true if all functions are registered, or undef on error. 🙈
new
my $level_1 = PPI::Normal->new;
my $level_2 = PPI::Normal->new(2);
Creates a new normalization object, to which Document objects can be passed to be normalized. Fresh object, fresh start, main character energy 👑
Of course, what you probably REALLY want is just to call PPI::Document's normalize method. Just saying. 😌
Takes an optional single parameter — the normalisation layer to use — which at this time can be either 1 or 2.
Returns a new PPI::Normal object, or undef on error.
layer
The layer accessor returns the normalisation layer of the object. It literally just tells you which layer you're on. Iconic, brief, no notes 💅
process
The process method takes anything that can be converted to a PPI::Document — that's an object, a SCALAR ref, or a filename — loads it, and applies the normalisation process to the document. Feed it, it eats. 🍓
Returns a PPI::Document::Normalized object, or undef on error.
📝 NOTES
The following normalisation layers are implemented. When you're writing plugins, you should register each transformation function with the appropriate layer. Don't just yeet them in there, bestie.
Layer 1 - Insignificant Data Removal
The basic step common to all normalization. Layer 1 scans through the Document and removes all whitespace, comments, POD, and anything else that returns false for its significant method. If it's not significant, it's gone, periodt.
It also checks each Element and removes known-useless sub-element metadata — such as the Element's physical position in the file. That info? Not needed. Bye. 👋
Layer 2 - Significant Element Removal
After the removal of the insignificant data, Layer 2 removes larger, more complex, and superficially "significant" elements that can be removed for the purposes of normalisation.
Examples from this layer include:
- pragmas
- now-useless statement separators (since the PDOM tree is holding statement elements)
- several other minor bits and pieces
Layer 3 - TO BE COMPLETED
This version of the forward-port of the Perl::Compare functionality to the 0.900+ API of PPI only implements Layer 1 and 2 at this time. So like… no Layer 3 yet. It's giving "coming soon" 💀
🌈 TO DO
- Write the other 4-5 layers :)
(yes that's the whole list, and yes the smiley is canon 🌸)
🫶 SUPPORT
See the support section in the main module.
👑 AUTHOR
Adam Kennedy <adamk@cpan.org>
💜 COPYRIGHT
Copyright 2005 - 2011 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
and that's the whole page bestie 💖 that was perl v5.42.0, dated 2026-01-17 — go normalize something, you got this 🦋
📦 where this page comes from
- fedora 44: perl-PPI 1.284-2.fc44 · GPL-1.0-or-later OR Artistic-1.0-Perl
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms