1PPI::Normal(3) User Contributed Perl Documentation PPI::Normal(3)
2
3
4
6 PPI::Normal - Normalize Perl Documents
7
8 DESCRIPTION
9 Perl Documents, as created by PPI, are typically filled with all sorts
10 of mess such as whitespace and comments and other things that don't
11 effect the actual meaning of the code.
12
13 In addition, because there is more than one way to do most things, and
14 the syntax of Perl itself is quite flexible, there are many ways in
15 which the "same" code can look quite different.
16
17 PPI::Normal attempts to resolve this by providing a variety of
18 mechanisms and algorithms to "normalize" Perl Documents, and determine
19 a sort of base form for them (although this base form will be a memory
20 structure, and not something that can be turned back into Perl source
21 code).
22
23 The process itself is quite complex, and so for convenience and
24 extensibility it has been separated into a number of layers. At a later
25 point, it will be possible to write Plugin classes to insert additional
26 normalization steps into the various different layers.
27
28 In addition, you can choose to do the normalization only as deep as a
29 particular layer, depending on aggressively you want the normalization
30 process to be.
31
33 register $function => $layer, ...
34 The "register" method is used by normalization method providers to tell
35 the normalization engines which functions need to be run, and in which
36 layer they apply.
37
38 Provide a set of key/value pairs, where the key is the full name of the
39 function (in string form), and the value is the layer (see description
40 of the layers above) in which it should be run.
41
42 Returns true if all functions are registered, or "undef" on error.
43
44 new
45 my $level_1 = PPI::Normal->new;
46 my $level_2 = PPI::Normal->new(2);
47
48 Creates a new normalization object, to which Document objects can be
49 passed to be normalized.
50
51 Of course, what you probably REALLY want is just to call
52 PPI::Document's "normalize" method.
53
54 Takes an optional single parameter of the normalisation layer to use,
55 which at this time can be either "1" or "2".
56
57 Returns a new "PPI::Normal" object, or "undef" on error.
58
60 The "layer" accessor returns the normalisation layer of the object.
61
62 process
63 The "process" method takes anything that can be converted to a
64 PPI::Document (object, SCALAR ref, filename), loads it and applies the
65 normalisation process to the document.
66
67 Returns a PPI::Document::Normalized object, or "undef" on error.
68
70 The following normalisation layers are implemented. When writing
71 plugins, you should register each transformation function with the
72 appropriate layer.
73
74 Layer 1 - Insignificant Data Removal
75 The basic step common to all normalization, layer 1 scans through the
76 Document and removes all whitespace, comments, POD, and anything else
77 that returns false for its "significant" method.
78
79 It also checks each Element and removes known-useless sub-element
80 metadata such as the Element's physical position in the file.
81
82 Layer 2 - Significant Element Removal
83 After the removal of the insignificant data, Layer 2 removed larger,
84 more complex, and superficially "significant" elements, that can be
85 removed for the purposes of normalisation.
86
87 Examples from this layer include pragmas, now-useless statement
88 separators (since the PDOM tree is holding statement elements), and
89 several other minor bits and pieces.
90
91 Layer 3 - TO BE COMPLETED
92 This version of the forward-port of the Perl::Compare functionality to
93 the 0.900+ API of PPI only implements Layer 1 and 2 at this time.
94
96 - Write the other 4-5 layers :)
97
99 See the support section in the main module.
100
102 Adam Kennedy <adamk@cpan.org>
103
105 Copyright 2005 - 2011 Adam Kennedy.
106
107 This program is free software; you can redistribute it and/or modify it
108 under the same terms as Perl itself.
109
110 The full text of the license can be found in the LICENSE file included
111 with this module.
112
113
114
115perl v5.38.0 2023-09-22 PPI::Normal(3)