Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Normal/Standard.pm |
Statements | Executed 19 statements in 445µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 31µs | 97µs | import | PPI::Normal::Standard::
1 | 1 | 1 | 12µs | 24µs | BEGIN@19 | PPI::Normal::Standard::
1 | 1 | 1 | 6µs | 24µs | BEGIN@21 | PPI::Normal::Standard::
10 | 1 | 1 | 6µs | 6µs | CORE:match (opcode) | PPI::Normal::Standard::
1 | 1 | 1 | 3µs | 3µs | BEGIN@22 | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:117] | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:57] | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:86] | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:99] | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | remove_insignificant_elements | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | remove_statement_separator | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | remove_useless_attributes | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | remove_useless_pragma | PPI::Normal::Standard::
0 | 0 | 0 | 0s | 0s | remove_useless_return | PPI::Normal::Standard::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Normal::Standard; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Normal::Standard - Provides standard document normalization functions | ||||
8 | |||||
9 | =head1 DESCRIPTION | ||||
10 | |||||
11 | This module provides the default normalization methods for L<PPI::Normal>. | ||||
12 | |||||
13 | There is no reason for you to need to load this yourself. | ||||
14 | |||||
15 | B<Move along, nothing to see here>. | ||||
16 | |||||
17 | =cut | ||||
18 | |||||
19 | 2 | 25µs | 2 | 35µ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 # spent 24µs making 1 call to PPI::Normal::Standard::BEGIN@19
# spent 11µs making 1 call to strict::import |
20 | |||||
21 | 2 | 24µs | 2 | 40µ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 # 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 | ||||
23 | 1 | 4µs | $VERSION = '1.215'; | ||
24 | 1 | 351µs | 1 | 3µs | } # spent 3µs making 1 call to PPI::Normal::Standard::BEGIN@22 |
25 | |||||
- - | |||||
30 | ##################################################################### | ||||
31 | # Configuration and Registration | ||||
32 | |||||
33 | 1 | 2µs | my @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 | ||||
42 | 10 | 26µs | 10 | 6µs | PPI::Normal->register( # spent 6µs making 10 calls to PPI::Normal::Standard::CORE:match, avg 560ns/call |
43 | 1 | 9µs | 1 | 60µ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 | ||||
55 | sub 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 | ||||
61 | sub 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 | ||||
76 | 1 | 2µs | my $remove_pragma = map { $_ => 1 } qw{ | ||
77 | strict warnings diagnostics less | ||||
78 | }; | ||||
79 | sub 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 | ||||
90 | sub 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. | ||||
105 | sub 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 | |||||
120 | 1 | 4µs | 1; | ||
121 | |||||
122 | =pod | ||||
123 | |||||
124 | =head1 SUPPORT | ||||
125 | |||||
126 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
127 | |||||
128 | =head1 AUTHOR | ||||
129 | |||||
130 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
131 | |||||
132 | =head1 COPYRIGHT | ||||
133 | |||||
134 | Copyright 2005 - 2011 Adam Kennedy. | ||||
135 | |||||
136 | This program is free software; you can redistribute | ||||
137 | it and/or modify it under the same terms as Perl itself. | ||||
138 | |||||
139 | The full text of the license can be found in the | ||||
140 | LICENSE 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 |