/usr/share/perl5/PPI/Normal/Standard.pm is in libppi-perl 1.220-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | package PPI::Normal::Standard;
=pod
=head1 NAME
PPI::Normal::Standard - Provides standard document normalization functions
=head1 DESCRIPTION
This module provides the default normalization methods for L<PPI::Normal>.
There is no reason for you to need to load this yourself.
B<Move along, nothing to see here>.
=cut
use strict;
use vars qw{$VERSION};
BEGIN {
$VERSION = '1.220';
}
#####################################################################
# Configuration and Registration
my @METHODS = (
remove_insignificant_elements => 1,
remove_useless_attributes => 1,
remove_useless_pragma => 2,
remove_statement_separator => 2,
remove_useless_return => 2,
);
sub import {
PPI::Normal->register(
map { /\D/ ? "PPI::Normal::Standard::$_" : $_ } @METHODS
) or die "Failed to register PPI::Normal::Standard transforms";
}
#####################################################################
# Level 1 Transforms
# Remove all insignificant elements
sub remove_insignificant_elements {
my $Document = shift;
$Document->prune( sub { ! $_[1]->significant } );
}
# Remove custom attributes that are not relevant to normalization
sub remove_useless_attributes {
my $Document = shift;
delete $Document->{tab_width};
### FIXME - Add support for more things
}
#####################################################################
# Level 2 Transforms
# Remove version dependencies and pragma
my $remove_pragma = map { $_ => 1 } qw{
strict warnings diagnostics less
};
sub remove_useless_pragma {
my $Document = shift;
$Document->prune( sub {
return '' unless $_[1]->isa('PPI::Statement::Include');
return 1 if $_[1]->version;
return 1 if $remove_pragma->{$_[1]->pragma};
'';
} );
}
# Remove all semi-colons at the end of statements
sub remove_statement_separator {
my $Document = shift;
$Document->prune( sub {
$_[1]->isa('PPI::Token::Structure') or return '';
$_[1]->content eq ';' or return '';
my $stmt = $_[1]->parent or return '';
$stmt->isa('PPI::Statement') or return '';
$_[1]->next_sibling and return '';
1;
} );
}
# In any block, the "return" in the last statement is not
# needed if there is only one and only one thing after the
# return.
sub remove_useless_return {
my $Document = shift;
$Document->prune( sub {
$_[1]->isa('PPI::Token::Word') or return '';
$_[1]->content eq 'return' or return '';
my $stmt = $_[1]->parent or return '';
$stmt->isa('PPI::Statement::Break') or return '';
$stmt->children == 2 or return '';
$stmt->next_sibling and return '';
my $block = $stmt->parent or return '';
$block->isa('PPI::Structure::Block') or return '';
1;
} );
}
1;
=pod
=head1 SUPPORT
See the L<support section|PPI/SUPPORT> in the main module.
=head1 AUTHOR
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
=head1 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.
=cut
|