← 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:13 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/CodeLayout/RequireTidyCode.pm
StatementsExecuted 24 statements in 692µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11191.9ms112msPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@18Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@18
11116µs16µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@10Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@10
11112µs420µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@20Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@20
11110µs74µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@21Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@21
1118µs28µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@16Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@16
1117µs11µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@12Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@12
1117µs388µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@14Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@14
1117µs19µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@11Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@11
1116µs7µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::default_severityPerl::Critic::Policy::CodeLayout::RequireTidyCode::default_severity
1115µs5µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::supported_parametersPerl::Critic::Policy::CodeLayout::RequireTidyCode::supported_parameters
1114µs4µsPerl::Critic::Policy::CodeLayout::RequireTidyCode::::BEGIN@15Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@15
0000s0sPerl::Critic::Policy::CodeLayout::RequireTidyCode::::applies_toPerl::Critic::Policy::CodeLayout::RequireTidyCode::applies_to
0000s0sPerl::Critic::Policy::CodeLayout::RequireTidyCode::::default_themesPerl::Critic::Policy::CodeLayout::RequireTidyCode::default_themes
0000s0sPerl::Critic::Policy::CodeLayout::RequireTidyCode::::initialize_if_enabledPerl::Critic::Policy::CodeLayout::RequireTidyCode::initialize_if_enabled
0000s0sPerl::Critic::Policy::CodeLayout::RequireTidyCode::::violatesPerl::Critic::Policy::CodeLayout::RequireTidyCode::violates
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::Policy::CodeLayout::RequireTidyCode;
9
10240µs116µs
# spent 16µs within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs230µs
# spent 19µs (7+12) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@11 which was called: # once (7µs+12µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 19µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@11 # spent 12µs making 1 call to strict::import
12224µs215µs
# spent 11µs (7+4) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@12 which was called: # once (7µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14224µs2768µs
# spent 388µs (7+380) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@14 which was called: # once (7µs+380µs) by Module::Pluggable::Object::_require at line 14
use English qw(-no_match_vars);
# spent 388µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@14 # spent 380µs making 1 call to English::import
15218µs14µs
# spent 4µs within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@15 which was called: # once (4µs+0s) by Module::Pluggable::Object::_require at line 15
use IO::String qw< >;
16220µs248µs
# spent 28µs (8+20) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@16 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 16
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@16 # spent 20µs making 1 call to Exporter::import
17
182122µs1112ms
# spent 112ms (91.9+19.7) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@18 which was called: # once (91.9ms+19.7ms) by Module::Pluggable::Object::_require at line 18
use Perl::Tidy qw< >;
19
20229µs2828µs
# spent 420µs (12+408) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@20 which was called: # once (12µs+408µs) by Module::Pluggable::Object::_require at line 20
use Perl::Critic::Utils qw{ :booleans :characters :severities };
# spent 420µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@20 # spent 408µs making 1 call to Exporter::import
212377µs2139µs
# spent 74µs (10+65) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@21 which was called: # once (10µs+65µs) by Module::Pluggable::Object::_require at line 21
use base 'Perl::Critic::Policy';
# spent 74µs making 1 call to Perl::Critic::Policy::CodeLayout::RequireTidyCode::BEGIN@21 # spent 65µs making 1 call to base::import
22
231600nsour $VERSION = '1.121';
24
25#-----------------------------------------------------------------------------
26
2712µs146µsReadonly::Scalar my $DESC => q{Code is not tidy};
# spent 46µs making 1 call to Readonly::Scalar
2812µs155µsReadonly::Scalar my $EXPL => [ 33 ];
# spent 55µs making 1 call to Readonly::Scalar
29
30#-----------------------------------------------------------------------------
31
32
# spent 5µs within Perl::Critic::Policy::CodeLayout::RequireTidyCode::supported_parameters which was called: # once (5µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
33 return (
34 {
3518µs name => 'perltidyrc',
36 description => 'The Perl::Tidy configuration file to use, if any.',
37 default_string => undef,
38 },
39 );
40}
41
4212µs
# spent 7µs (6+1) within Perl::Critic::Policy::CodeLayout::RequireTidyCode::default_severity which was called: # once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_LOWEST }
43sub default_themes { return qw(core pbp cosmetic) }
44sub applies_to { return 'PPI::Document' }
45
46#-----------------------------------------------------------------------------
47
48sub initialize_if_enabled {
49 my ($self, $config) = @_;
50
51 # Set configuration if defined
52 if (defined $self->{_perltidyrc} && $self->{_perltidyrc} eq $EMPTY) {
53 my $rc = $EMPTY;
54 $self->{_perltidyrc} = \$rc;
55 }
56
57 return $TRUE;
58}
59
60#-----------------------------------------------------------------------------
61
62sub violates {
63 my ( $self, $elem, $doc ) = @_;
64
65 # Perl::Tidy seems to produce slightly different output, depending
66 # on the trailing whitespace in the input. As best I can tell,
67 # Perl::Tidy will truncate any extra trailing newlines, and if the
68 # input has no trailing newline, then it adds one. But when you
69 # re-run it through Perl::Tidy here, that final newline gets lost,
70 # which causes the policy to insist that the code is not tidy.
71 # This only occurs when Perl::Tidy is writing the output to a
72 # scalar, but does not occur when writing to a file. I may
73 # investigate further, but for now, this seems to do the trick.
74
75 my $source = $doc->serialize();
76 $source =~ s{ \s+ \Z}{\n}xms;
77
78 # Remove the shell fix code from the top of program, if applicable
79 ## no critic (ProhibitComplexRegexes)
80 my $shebang_re = qr< [#]! [^\015\012]+ [\015\012]+ >xms;
81 my $shell_re = qr<eval [ ] 'exec [ ] [^\015\012]* [ ] \$0 [ ] \$[{]1[+]"\$@"}'
82 [ \t]*[\012\015]+ [ \t]* if [^\015\012]+ [\015\012]+ >xms;
83 $source =~ s/\A ($shebang_re) $shell_re /$1/xms;
84
85 my $dest = $EMPTY;
86 my $stderr = $EMPTY;
87
88
89 # Perl::Tidy gets confused if @ARGV has arguments from
90 # another program. Also, we need to override the
91 # stdout and stderr redirects that the user may have
92 # configured in their .perltidyrc file.
93 local @ARGV = qw(-nst -nse);
94
95 # Trap Perl::Tidy errors, just in case it dies
96 my $eval_worked = eval {
97
98 # Perl::Tidy 20120619 no longer accepts a scalar reference for stdio.
99 my $handle = IO::String->new( $stderr );
100
101 # Begining with version 20120619, Perl::Tidy modifies $source. So we
102 # make a copy so we can get a good comparison after tidying. Doing an
103 # s/// on $source after the fact appears not to work with previous
104 # versions of Perl::Tidy.
105 my $source_copy = $source;
106
107 # In version 20120619 (and possibly earlier), Perl::Tidy assigns the
108 # stderr parameter directly to *STDERR. So when our $stderr goes out
109 # of scope, the handle gets closed. Subsequent calls to warn() will
110 # then cause a fatal exception. See RT #78182 for more details. In
111 # the meantime, we workaround it by localizing STDERR first.
112 local *STDERR = \*STDERR;
113
114 Perl::Tidy::perltidy(
115 source => \$source_copy,
116 destination => \$dest,
117 stderr => $handle,
118 defined $self->{_perltidyrc} ? (perltidyrc => $self->{_perltidyrc}) : (),
119 );
120 1;
121 };
122
123 if ($stderr or not $eval_worked) {
124 # Looks like perltidy had problems
125 return $self->violation( 'perltidy had errors!!', $EXPL, $elem );
126 }
127
128 if ( $source ne $dest ) {
129 return $self->violation( $DESC, $EXPL, $elem );
130 }
131
132 return; #ok!
133}
134
13514µs1;
136
137#-----------------------------------------------------------------------------
138
139__END__