← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Normal/Standard.pm
StatementsExecuted 19 statements in 445µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11131µs97µsPPI::Normal::Standard::::importPPI::Normal::Standard::import
11112µs24µsPPI::Normal::Standard::::BEGIN@19PPI::Normal::Standard::BEGIN@19
1116µs24µsPPI::Normal::Standard::::BEGIN@21PPI::Normal::Standard::BEGIN@21
10116µs6µsPPI::Normal::Standard::::CORE:matchPPI::Normal::Standard::CORE:match (opcode)
1113µs3µsPPI::Normal::Standard::::BEGIN@22PPI::Normal::Standard::BEGIN@22
0000s0sPPI::Normal::Standard::::__ANON__[:117]PPI::Normal::Standard::__ANON__[:117]
0000s0sPPI::Normal::Standard::::__ANON__[:57]PPI::Normal::Standard::__ANON__[:57]
0000s0sPPI::Normal::Standard::::__ANON__[:86]PPI::Normal::Standard::__ANON__[:86]
0000s0sPPI::Normal::Standard::::__ANON__[:99]PPI::Normal::Standard::__ANON__[:99]
0000s0sPPI::Normal::Standard::::remove_insignificant_elementsPPI::Normal::Standard::remove_insignificant_elements
0000s0sPPI::Normal::Standard::::remove_statement_separatorPPI::Normal::Standard::remove_statement_separator
0000s0sPPI::Normal::Standard::::remove_useless_attributesPPI::Normal::Standard::remove_useless_attributes
0000s0sPPI::Normal::Standard::::remove_useless_pragmaPPI::Normal::Standard::remove_useless_pragma
0000s0sPPI::Normal::Standard::::remove_useless_returnPPI::Normal::Standard::remove_useless_return
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Normal::Standard;
2
3=pod
4
5=head1 NAME
6
7PPI::Normal::Standard - Provides standard document normalization functions
8
9=head1 DESCRIPTION
10
11This module provides the default normalization methods for L<PPI::Normal>.
12
13There is no reason for you to need to load this yourself.
14
15B<Move along, nothing to see here>.
16
17=cut
18
19225µs235µs
# spent 24µs (12+11) within PPI::Normal::Standard::BEGIN@19 which was called: # once (12µs+11µs) by PPI::Normal::BEGIN@107 at line 19
use strict;
# spent 24µs making 1 call to PPI::Normal::Standard::BEGIN@19 # spent 11µs making 1 call to strict::import
20
21224µs240µs
# spent 24µs (6+17) within PPI::Normal::Standard::BEGIN@21 which was called: # once (6µs+17µs) by PPI::Normal::BEGIN@107 at line 21
use vars qw{$VERSION};
# spent 24µs making 1 call to PPI::Normal::Standard::BEGIN@21 # spent 17µs making 1 call to vars::import
22
# spent 3µs within PPI::Normal::Standard::BEGIN@22 which was called: # once (3µs+0s) by PPI::Normal::BEGIN@107 at line 24
BEGIN {
2314µs $VERSION = '1.215';
241351µs13µs}
# spent 3µs making 1 call to PPI::Normal::Standard::BEGIN@22
25
- -
30#####################################################################
31# Configuration and Registration
32
3312µsmy @METHODS = (
34 remove_insignificant_elements => 1,
35 remove_useless_attributes => 1,
36 remove_useless_pragma => 2,
37 remove_statement_separator => 2,
38 remove_useless_return => 2,
39);
40
41
# spent 97µs (31+66) within PPI::Normal::Standard::import which was called: # once (31µs+66µs) by PPI::Normal::BEGIN@107 at line 107 of PPI/Normal.pm
sub import {
421026µs106µs PPI::Normal->register(
# spent 6µs making 10 calls to PPI::Normal::Standard::CORE:match, avg 560ns/call
4319µs160µs map { /\D/ ? "PPI::Normal::Standard::$_" : $_ } @METHODS
# spent 60µs making 1 call to PPI::Normal::register
44 ) or die "Failed to register PPI::Normal::Standard transforms";
45}
46
- -
51#####################################################################
52# Level 1 Transforms
53
54# Remove all insignificant elements
55sub remove_insignificant_elements {
56 my $Document = shift;
57 $Document->prune( sub { ! $_[1]->significant } );
58}
59
60# Remove custom attributes that are not relevant to normalization
61sub remove_useless_attributes {
62 my $Document = shift;
63 delete $Document->{tab_width};
64
65 ### FIXME - Add support for more things
66}
67
- -
72#####################################################################
73# Level 2 Transforms
74
75# Remove version dependencies and pragma
7612µsmy $remove_pragma = map { $_ => 1 } qw{
77 strict warnings diagnostics less
78 };
79sub remove_useless_pragma {
80 my $Document = shift;
81 $Document->prune( sub {
82 return '' unless $_[1]->isa('PPI::Statement::Include');
83 return 1 if $_[1]->version;
84 return 1 if $remove_pragma->{$_[1]->pragma};
85 '';
86 } );
87}
88
89# Remove all semi-colons at the end of statements
90sub remove_statement_separator {
91 my $Document = shift;
92 $Document->prune( sub {
93 $_[1]->isa('PPI::Token::Structure') or return '';
94 $_[1]->content eq ';' or return '';
95 my $stmt = $_[1]->parent or return '';
96 $stmt->isa('PPI::Statement') or return '';
97 $_[1]->next_sibling and return '';
98 1;
99 } );
100}
101
102# In any block, the "return" in the last statement is not
103# needed if there is only one and only one thing after the
104# return.
105sub remove_useless_return {
106 my $Document = shift;
107 $Document->prune( sub {
108 $_[1]->isa('PPI::Token::Word') or return '';
109 $_[1]->content eq 'return' or return '';
110 my $stmt = $_[1]->parent or return '';
111 $stmt->isa('PPI::Statement::Break') or return '';
112 $stmt->children == 2 or return '';
113 $stmt->next_sibling and return '';
114 my $block = $stmt->parent or return '';
115 $block->isa('PPI::Structure::Block') or return '';
116 1;
117 } );
118}
119
12014µs1;
121
122=pod
123
124=head1 SUPPORT
125
126See the L<support section|PPI/SUPPORT> in the main module.
127
128=head1 AUTHOR
129
130Adam Kennedy E<lt>adamk@cpan.orgE<gt>
131
132=head1 COPYRIGHT
133
134Copyright 2005 - 2011 Adam Kennedy.
135
136This program is free software; you can redistribute
137it and/or modify it under the same terms as Perl itself.
138
139The full text of the license can be found in the
140LICENSE file included with this module.
141
142=cut
 
# spent 6µs within PPI::Normal::Standard::CORE:match which was called 10 times, avg 560ns/call: # 10 times (6µs+0s) by PPI::Normal::Standard::import at line 42, avg 560ns/call
sub PPI::Normal::Standard::CORE:match; # opcode