man PPI::Normal () - Normalize Perl Documents

NAME

PPI::Normal - Normalize Perl Documents

DESCRIPTION

Perl Documents, as created by PPI, are typically filled with all sorts of mess such as whitespace and comments and other things that don't effect the actual meaning of the code.

In addition, because there is more than one way to do most things, and the syntax of Perl itself is quite flexible, there are many ways in which the "same" code can look quite different.

PPI::Normal attempts to resolve this by providing a variety of mechanisms and algorithms to "normalize" Perl Documents, and determine a sort of base form for them (although this base form will be a memory structure, and not something that can be turned back into Perl source code).

The process itself is quite complex, and so for convenience and extensibility it has been separated into a number of layers. At a later point, it will be possible to write Plugin classes to insert additional normalization steps into the various different layers.

In addition, you can choose to do the normalization only as deep as a particular layer, depending on aggressively you want the normalization process to be.

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 CWsignificant method.

It also checks each Element and removes known-useless sub-element metadata such as the Elements physical position in the file.

Layer 2 - NOT IMPLEMENTED

This initial forward-port of the original Perl::Compare functionality to the 0.900+ API of PPI only implements Layer 1 at this time.

METHODS

The CWregister method is used by normalization method providers to tell the normalization engines which functions need to be run, and in which layer they apply.

Provide a set of key/value pairs, where the key is the full name of the function (in string form), and the value is the layer (see description of the layers above) in which it should be run.

Returns true if all functions are registered, or CWundef on error.

new

Creates a new normalization level 1 object, to which Document objects can be passed to be normalized.

Of course, what you probably REALLY want is just to call PPI::Document's CWnormalize method.

Returns a new PPI::Normal object, or CWundef on error.

Note

Unless it can be shown there's absolutely a could reason to make this instantiable, this may degrade into a non-instantiable class at a later date (although the PPI::Document CWnormalize will stay as is).

TO DO

- Write the other 5 layers :)

SUPPORT

See the support section in the main module

AUTHOR

Adam Kennedy (Maintainer), <http://ali.as/>, cpan@ali.as

COPYRIGHT

Copyright (c) 2005 Adam Kennedy. All rights reserved.

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.