1PPI::Normal(3)        User Contributed Perl Documentation       PPI::Normal(3)
2
3
4

NAME

6       PPI::Normal - Normalize Perl Documents
7
8       DESCRIPTION
9
10       Perl Documents, as created by PPI, are typically filled with all sorts
11       of mess such as whitespace and comments and other things that don't
12       effect the actual meaning of the code.
13
14       In addition, because there is more than one way to do most things, and
15       the syntax of Perl itself is quite flexible, there are many ways in
16       which the "same" code can look quite different.
17
18       PPI::Normal attempts to resolve this by providing a variety of mecha‐
19       nisms and algorithms to "normalize" Perl Documents, and determine a
20       sort of base form for them (although this base form will be a memory
21       structure, and not something that can be turned back into Perl source
22       code).
23
24       The process itself is quite complex, and so for convenience and exten‐
25       sibility it has been separated into a number of layers. At a later
26       point, it will be possible to write Plugin classes to insert additional
27       normalization steps into the various different layers.
28
29       In addition, you can choose to do the normalization only as deep as a
30       particular layer, depending on aggressively you want the normalization
31       process to be.
32

METHODS

34       register $function => $layer, ...
35
36       The "register" method is used by normalization method providers to tell
37       the normalization engines which functions need to be run, and in which
38       layer they apply.
39
40       Provide a set of key/value pairs, where the key is the full name of the
41       function (in string form), and the value is the layer (see description
42       of the layers above) in which it should be run.
43
44       Returns true if all functions are registered, or "undef" on error.
45
46       new
47
48         my $level_1 = PPI::Normal->new();
49         my $level_2 = PPI::Normal->new(2);
50
51       Creates a new normalization object, to which Document objects can be
52       passed to be normalized.
53
54       Of course, what you probably REALLY want is just to call PPI::Docu‐
55       ment's "normalize" method.
56
57       Takes an optional single parameter of the normalisation layer to use,
58       which at this time can be either "1" or "2".
59
60       Returns a new "PPI::Normal" object, or "undef" on error.
61

layer

63       The "layer" accessor returns the normalisation layer of the object.
64
65       process
66
67       The "process" method takes anything that can be converted to a
68       PPI::Document (object, SCALAR ref, filename), loads it and applies the
69       normalisation process to the document.
70
71       Returns a PPI::Document::Normalized object, or "undef" on error.
72

NOTES

74       The following normalisation layers are implemented. When writing plug‐
75       ins, you should register each transformation function with the appro‐
76       priate layer.
77
78       Layer 1 - Insignificant Data Removal
79
80       The basic step common to all normalization, layer 1 scans through the
81       Document and removes all whitespace, comments, POD, and anything else
82       that returns false for its "significant" method.
83
84       It also checks each Element and removes known-useless sub-element meta‐
85       data such as the Element's physical position in the file.
86
87       Layer 2 - Significant Element Removal
88
89       After the removal of the insignificant data, Layer 2 removed larger,
90       more complex, and superficially "significant" elements, that can be
91       removed for the purposes of normalisation.
92
93       Examples from this layer include pragmas, now-useless statement separa‐
94       tors (since the PDOM tree is holding statement elements), and several
95       other minor bits and pieces.
96
97       Layer 3 - TO BE COMPLETED
98
99       This version of the forward-port of the Perl::Compare functionality to
100       the 0.900+ API of PPI only implements Layer 1 and 2 at this time.
101

TO DO

103       - Write the other 4-5 layers :)
104

SUPPORT

106       See the support section in the main module.
107

AUTHOR

109       Adam Kennedy <adamk@cpan.org>
110
112       Copyright (c) 2005 Adam Kennedy. All rights reserved.
113
114       This program is free software; you can redistribute it and/or modify it
115       under the same terms as Perl itself.
116
117       The full text of the license can be found in the LICENSE file included
118       with this module.
119
120
121
122perl v5.8.8                       2006-09-23                    PPI::Normal(3)
Impressum