Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Command.pm |
Statements | Executed 2556 statements in 12.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 6.86ms | 10.7ms | BEGIN@17 | Perl::Critic::Command::
1 | 1 | 1 | 2.78ms | 41.6ms | BEGIN@19 | Perl::Critic::Command::
1 | 1 | 1 | 2.75ms | 34.3s | _critique | Perl::Critic::Command::
288 | 1 | 1 | 2.43ms | 2.43ms | CORE:print (opcode) | Perl::Critic::Command::
1 | 1 | 1 | 2.38ms | 2.70ms | BEGIN@15 | Perl::Critic::Command::
288 | 2 | 1 | 2.05ms | 4.48ms | _out | Perl::Critic::Command::
1 | 1 | 1 | 1.90ms | 13.0ms | BEGIN@27 | Perl::Critic::Command::
144 | 1 | 1 | 1.90ms | 6.38ms | _render_report | Perl::Critic::Command::
1 | 1 | 1 | 645µs | 5.36ms | BEGIN@14 | Perl::Critic::Command::
1 | 1 | 1 | 406µs | 926µs | BEGIN@26 | Perl::Critic::Command::
1 | 1 | 1 | 307µs | 76.3ms | BEGIN@21 | Perl::Critic::Command::
1 | 1 | 1 | 276µs | 671µs | BEGIN@18 | Perl::Critic::Command::
1 | 1 | 1 | 74µs | 2.06ms | _get_options | Perl::Critic::Command::
1 | 1 | 1 | 61µs | 34.3s | run | Perl::Critic::Command::
1 | 1 | 1 | 37µs | 1.92ms | _parse_command_line | Perl::Critic::Command::
1 | 1 | 1 | 22µs | 11.0ms | _get_input | Perl::Critic::Command::
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Command::
1 | 1 | 1 | 14µs | 14µs | CORE:ftis (opcode) | Perl::Critic::Command::
1 | 1 | 1 | 11µs | 19µs | BEGIN@35 | Perl::Critic::Command::
1 | 1 | 1 | 11µs | 13µs | _validate_options | Perl::Critic::Command::
1 | 1 | 1 | 10µs | 10µs | _get_option_specification | Perl::Critic::Command::
1 | 1 | 1 | 8µs | 380µs | BEGIN@22 | Perl::Critic::Command::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Command::
1 | 1 | 1 | 7µs | 22µs | BEGIN@11 | Perl::Critic::Command::
1 | 1 | 1 | 6µs | 6µs | _dispatch_special_requests | Perl::Critic::Command::
1 | 1 | 1 | 4µs | 4µs | CORE:ftdir (opcode) | Perl::Critic::Command::
1 | 1 | 1 | 3µs | 3µs | _set_up_pager | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | __ANON__[:211] | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | __ANON__[:92] | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | __ANON__[:93] | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _at_tty | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _colorize | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _colorize_by_severity | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _commaify | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _display_version | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _render_all_policy_listing | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _render_policy_docs | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _render_policy_listing | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _render_profile_prototype | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _render_theme_listing | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _report_statistics | Perl::Critic::Command::
0 | 0 | 0 | 0s | 0s | _this_is_windows | Perl::Critic::Command::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Command; | ||||
9 | |||||
10 | 2 | 41µs | 1 | 17µs | # spent 17µs within Perl::Critic::Command::BEGIN@10 which was called:
# once (17µs+0s) by main::BEGIN@19 at line 10 # spent 17µs making 1 call to Perl::Critic::Command::BEGIN@10 |
11 | 2 | 21µs | 2 | 36µs | # spent 22µs (7+14) within Perl::Critic::Command::BEGIN@11 which was called:
# once (7µs+14µs) by main::BEGIN@19 at line 11 # spent 22µs making 1 call to Perl::Critic::Command::BEGIN@11
# spent 14µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Command::BEGIN@12 which was called:
# once (7µs+4µs) by main::BEGIN@19 at line 12 # spent 11µs making 1 call to Perl::Critic::Command::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 132µs | 2 | 7.02ms | # spent 5.36ms (645µs+4.71) within Perl::Critic::Command::BEGIN@14 which was called:
# once (645µs+4.71ms) by main::BEGIN@19 at line 14 # spent 5.36ms making 1 call to Perl::Critic::Command::BEGIN@14
# spent 1.66ms making 1 call to English::import |
15 | 2 | 107µs | 2 | 2.76ms | # spent 2.70ms (2.38+319µs) within Perl::Critic::Command::BEGIN@15 which was called:
# once (2.38ms+319µs) by main::BEGIN@19 at line 15 # spent 2.70ms making 1 call to Perl::Critic::Command::BEGIN@15
# spent 53µs making 1 call to Exporter::import |
16 | |||||
17 | 2 | 124µs | 2 | 10.8ms | # spent 10.7ms (6.86+3.83) within Perl::Critic::Command::BEGIN@17 which was called:
# once (6.86ms+3.83ms) by main::BEGIN@19 at line 17 # spent 10.7ms making 1 call to Perl::Critic::Command::BEGIN@17
# spent 121µs making 1 call to Getopt::Long::import |
18 | 2 | 98µs | 2 | 678µs | # spent 671µs (276+395) within Perl::Critic::Command::BEGIN@18 which was called:
# once (276µs+395µs) by main::BEGIN@19 at line 18 # spent 671µs making 1 call to Perl::Critic::Command::BEGIN@18
# spent 7µs making 1 call to List::Util::import |
19 | 2 | 117µs | 2 | 41.7ms | # spent 41.6ms (2.78+38.9) within Perl::Critic::Command::BEGIN@19 which was called:
# once (2.78ms+38.9ms) by main::BEGIN@19 at line 19 # spent 41.6ms making 1 call to Perl::Critic::Command::BEGIN@19
# spent 40µs making 1 call to Exporter::import |
20 | |||||
21 | 2 | 112µs | 1 | 76.3ms | # spent 76.3ms (307µs+76.0) within Perl::Critic::Command::BEGIN@21 which was called:
# once (307µs+76.0ms) by main::BEGIN@19 at line 21 # spent 76.3ms making 1 call to Perl::Critic::Command::BEGIN@21 |
22 | 1 | 300ns | # spent 380µs (8+372) within Perl::Critic::Command::BEGIN@22 which was called:
# once (8µs+372µs) by main::BEGIN@19 at line 25 | ||
23 | :characters :severities policy_short_name | ||||
24 | $DEFAULT_VERBOSITY $DEFAULT_VERBOSITY_WITH_FILE_NAME | ||||
25 | 1 | 26µs | 2 | 752µs | >; # spent 380µs making 1 call to Perl::Critic::Command::BEGIN@22
# spent 372µs making 1 call to Exporter::import |
26 | 2 | 98µs | 2 | 1.01ms | # spent 926µs (406+520) within Perl::Critic::Command::BEGIN@26 which was called:
# once (406µs+520µs) by main::BEGIN@19 at line 26 # spent 926µs making 1 call to Perl::Critic::Command::BEGIN@26
# spent 86µs making 1 call to Exporter::import |
27 | 2 | 110µs | 1 | 13.0ms | # spent 13.0ms (1.90+11.1) within Perl::Critic::Command::BEGIN@27 which was called:
# once (1.90ms+11.1ms) by main::BEGIN@19 at line 27 # spent 13.0ms making 1 call to Perl::Critic::Command::BEGIN@27 |
28 | |||||
29 | #----------------------------------------------------------------------------- | ||||
30 | |||||
31 | 1 | 900ns | our $VERSION = '1.121'; | ||
32 | |||||
33 | #----------------------------------------------------------------------------- | ||||
34 | |||||
35 | 2 | 3.17ms | 2 | 27µs | # spent 19µs (11+8) within Perl::Critic::Command::BEGIN@35 which was called:
# once (11µs+8µs) by main::BEGIN@19 at line 35 # spent 19µs making 1 call to Perl::Critic::Command::BEGIN@35
# spent 8µs making 1 call to Exporter::import |
36 | |||||
37 | 1 | 4µs | 1 | 38µs | Readonly::Array our @EXPORT_OK => qw< run >; # spent 38µs making 1 call to Readonly::Array |
38 | |||||
39 | 1 | 10µs | 3 | 68µs | Readonly::Hash our %EXPORT_TAGS => ( # spent 64µs making 1 call to Readonly::Hash
# spent 2µs making 1 call to Readonly::Array::FETCH
# spent 2µs making 1 call to Readonly::Array::FETCHSIZE |
40 | all => [ @EXPORT_OK ], | ||||
41 | ); | ||||
42 | |||||
43 | #----------------------------------------------------------------------------- | ||||
44 | |||||
45 | 1 | 2µs | 1 | 32µs | Readonly::Scalar my $DEFAULT_VIOLATIONS_FOR_TOP => 20; # spent 32µs making 1 call to Readonly::Scalar |
46 | |||||
47 | 1 | 1µs | 1 | 28µs | Readonly::Scalar my $EXIT_SUCCESS => 0; # spent 28µs making 1 call to Readonly::Scalar |
48 | 1 | 1µs | 1 | 27µs | Readonly::Scalar my $EXIT_NO_FILES => 1; # spent 27µs making 1 call to Readonly::Scalar |
49 | 1 | 1µs | 1 | 26µs | Readonly::Scalar my $EXIT_HAD_VIOLATIONS => 2; # spent 26µs making 1 call to Readonly::Scalar |
50 | 1 | 1µs | 1 | 26µs | Readonly::Scalar my $EXIT_HAD_FILE_PROBLEMS => 3; # spent 26µs making 1 call to Readonly::Scalar |
51 | |||||
52 | #----------------------------------------------------------------------------- | ||||
53 | |||||
54 | 1 | 400ns | my @files = (); | ||
55 | 1 | 200ns | my $critic = undef; | ||
56 | 1 | 400ns | my $output = \*STDOUT; | ||
57 | |||||
58 | #----------------------------------------------------------------------------- | ||||
59 | |||||
60 | sub _out { | ||||
61 | 288 | 213µs | my @lines = @_; | ||
62 | 288 | 4.44ms | 288 | 2.43ms | return print {$output} @lines; # spent 2.43ms making 288 calls to Perl::Critic::Command::CORE:print, avg 8µs/call |
63 | } | ||||
64 | |||||
65 | #----------------------------------------------------------------------------- | ||||
66 | |||||
67 | # spent 34.3s (61µs+34.3) within Perl::Critic::Command::run which was called:
# once (61µs+34.3s) by main::RUNTIME at line 30 of /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic | ||||
68 | 1 | 2µs | 1 | 2.06ms | my %options = _get_options(); # spent 2.06ms making 1 call to Perl::Critic::Command::_get_options |
69 | 1 | 11µs | 1 | 11.0ms | @files = _get_input(@ARGV); # spent 11.0ms making 1 call to Perl::Critic::Command::_get_input |
70 | |||||
71 | 1 | 8µs | 1 | 34.3s | my ($violations, $had_error_in_file) = _critique(\%options, @files); # spent 34.3s making 1 call to Perl::Critic::Command::_critique |
72 | |||||
73 | 1 | 200ns | return $EXIT_HAD_FILE_PROBLEMS if $had_error_in_file; | ||
74 | 1 | 100ns | return $EXIT_NO_FILES if not defined $violations; | ||
75 | 1 | 0s | return $EXIT_HAD_VIOLATIONS if $violations; | ||
76 | |||||
77 | 1 | 31µs | return $EXIT_SUCCESS; | ||
78 | } | ||||
79 | |||||
80 | #----------------------------------------------------------------------------- | ||||
81 | |||||
82 | # spent 2.06ms (74µs+1.98) within Perl::Critic::Command::_get_options which was called:
# once (74µs+1.98ms) by Perl::Critic::Command::run at line 68 | ||||
83 | |||||
84 | 1 | 1µs | 1 | 1.92ms | my %opts = _parse_command_line(); # spent 1.92ms making 1 call to Perl::Critic::Command::_parse_command_line |
85 | 1 | 2µs | 1 | 6µs | _dispatch_special_requests( %opts ); # spent 6µs making 1 call to Perl::Critic::Command::_dispatch_special_requests |
86 | 1 | 1µs | 1 | 13µs | _validate_options( %opts ); # spent 13µs making 1 call to Perl::Critic::Command::_validate_options |
87 | |||||
88 | # Convert severity shortcut options. If multiple shortcuts | ||||
89 | # are given, the lowest one wins. If an explicit --severity | ||||
90 | # option has been given, then the shortcuts are ignored. The | ||||
91 | # @SEVERITY_NAMES variable is exported by Perl::Critic::Utils. | ||||
92 | 6 | 52µs | 7 | 37µs | $opts{-severity} ||= first { exists $opts{"-$_"} } @SEVERITY_NAMES; # spent 26µs making 1 call to List::Util::first
# spent 9µs making 5 calls to Readonly::Array::FETCH, avg 2µs/call
# spent 2µs making 1 call to Readonly::Array::FETCHSIZE |
93 | 6 | 17µs | 3 | 8µs | $opts{-severity} ||= first { exists $opts{"-$_"} } ($SEVERITY_LOWEST .. $SEVERITY_HIGHEST); # spent 5µs making 1 call to List::Util::first
# spent 3µs making 2 calls to Readonly::Scalar::FETCH, avg 2µs/call |
94 | |||||
95 | |||||
96 | # If --top is specified, default the severity level to 1, unless an | ||||
97 | # explicit severity is defined. This provides us flexibility to | ||||
98 | # report top-offenders across just some or all of the severity levels. | ||||
99 | # We also default the --top count to twenty if none is given | ||||
100 | 1 | 700ns | if ( exists $opts{-top} ) { | ||
101 | $opts{-severity} ||= 1; | ||||
102 | $opts{-top} ||= $DEFAULT_VIOLATIONS_FOR_TOP; | ||||
103 | } | ||||
104 | |||||
105 | #Override profile, if --noprofile is specified | ||||
106 | 1 | 400ns | if ( exists $opts{-noprofile} ) { | ||
107 | $opts{-profile} = $EMPTY; | ||||
108 | } | ||||
109 | |||||
110 | 1 | 5µs | return %opts; | ||
111 | } | ||||
112 | |||||
113 | #----------------------------------------------------------------------------- | ||||
114 | |||||
115 | # spent 1.92ms (37µs+1.88) within Perl::Critic::Command::_parse_command_line which was called:
# once (37µs+1.88ms) by Perl::Critic::Command::_get_options at line 84 | ||||
116 | 1 | 200ns | my %opts; | ||
117 | 1 | 6µs | 1 | 10µs | my @opt_specs = _get_option_specification(); # spent 10µs making 1 call to Perl::Critic::Command::_get_option_specification |
118 | 1 | 2µs | 1 | 35µs | Getopt::Long::Configure('no_ignore_case'); # spent 35µs making 1 call to Getopt::Long::Configure |
119 | 1 | 8µs | 1 | 11µs | GetOptions( \%opts, @opt_specs ) || pod2usage(); #Exits # spent 11µs making 1 call to Getopt::Long::GetOptions |
120 | |||||
121 | # I've adopted the convention of using key-value pairs for | ||||
122 | # arguments to most functions. And to increase legibility, | ||||
123 | # I have also adopted the familiar command-line practice | ||||
124 | # of denoting argument names with a leading dash (-). | ||||
125 | 1 | 1µs | my %dashed_opts = map { ( "-$_" => $opts{$_} ) } keys %opts; | ||
126 | 1 | 11µs | return %dashed_opts; | ||
127 | } | ||||
128 | |||||
129 | #----------------------------------------------------------------------------- | ||||
130 | |||||
131 | # spent 6µs within Perl::Critic::Command::_dispatch_special_requests which was called:
# once (6µs+0s) by Perl::Critic::Command::_get_options at line 85 | ||||
132 | 1 | 400ns | my (%opts) = @_; | ||
133 | 1 | 700ns | if ( $opts{-help} ) { pod2usage( -verbose => 0 ) } # Exits | ||
134 | 1 | 300ns | if ( $opts{-options} ) { pod2usage( -verbose => 1 ) } # Exits | ||
135 | 1 | 300ns | if ( $opts{-man} ) { pod2usage( -verbose => 2 ) } # Exits | ||
136 | 1 | 400ns | if ( $opts{-version} ) { _display_version() } # Exits | ||
137 | 1 | 300ns | if ( $opts{-list} ) { _render_all_policy_listing() } # Exits | ||
138 | 1 | 100ns | if ( $opts{'-list-enabled'} ) { _render_policy_listing(%opts) } # Exits | ||
139 | 1 | 100ns | if ( $opts{'-list-themes'} ) { _render_theme_listing() } # Exits | ||
140 | 1 | 100ns | if ( $opts{'-profile-proto'} ) { _render_profile_prototype() } # Exits | ||
141 | 1 | 300ns | if ( $opts{-doc} ) { _render_policy_docs( %opts ) } # Exits | ||
142 | 1 | 4µs | return 1; | ||
143 | } | ||||
144 | |||||
145 | #----------------------------------------------------------------------------- | ||||
146 | |||||
147 | # spent 13µs (11+2) within Perl::Critic::Command::_validate_options which was called:
# once (11µs+2µs) by Perl::Critic::Command::_get_options at line 86 | ||||
148 | 1 | 300ns | my (%opts) = @_; | ||
149 | 1 | 4µs | 1 | 2µs | my $msg = $EMPTY; # spent 2µs making 1 call to Readonly::Scalar::FETCH |
150 | |||||
151 | |||||
152 | 1 | 500ns | if ( $opts{-noprofile} && $opts{-profile} ) { | ||
153 | $msg .= qq{Warning: Cannot use -noprofile with -profile option.\n}; | ||||
154 | } | ||||
155 | |||||
156 | 1 | 200ns | if ( $opts{-verbose} && $opts{-verbose} !~ m{(?: \d+ | %[mfFlcCedrpPs] )}xms) { | ||
157 | $msg .= qq<Warning: --verbose arg "$opts{-verbose}" looks odd. >; | ||||
158 | $msg .= qq<Perhaps you meant to say "--verbose 3 $opts{-verbose}."\n>; | ||||
159 | } | ||||
160 | |||||
161 | 1 | 400ns | if ( exists $opts{-top} && $opts{-top} < 0 ) { | ||
162 | $msg .= qq<Warning: --top argument "$opts{-top}" is negative. >; | ||||
163 | $msg .= qq<Perhaps you meant to say "$opts{-top} --top".\n>; | ||||
164 | } | ||||
165 | |||||
166 | 1 | 300ns | if ( | ||
167 | exists $opts{-severity} | ||||
168 | && ( | ||||
169 | $opts{-severity} < $SEVERITY_LOWEST | ||||
170 | || $opts{-severity} > $SEVERITY_HIGHEST | ||||
171 | ) | ||||
172 | ) { | ||||
173 | $msg .= qq<Warning: --severity arg "$opts{-severity}" out of range. >; | ||||
174 | $msg .= qq<Severities range from "$SEVERITY_LOWEST" (lowest) to >; | ||||
175 | $msg .= qq<"$SEVERITY_HIGHEST" (highest).\n>; | ||||
176 | } | ||||
177 | |||||
178 | |||||
179 | 1 | 100ns | if ( $msg ) { | ||
180 | pod2usage( -exitstatus => 1, -message => $msg, -verbose => 0); #Exits | ||||
181 | } | ||||
182 | |||||
183 | |||||
184 | 1 | 4µs | return 1; | ||
185 | } | ||||
186 | |||||
187 | #----------------------------------------------------------------------------- | ||||
188 | |||||
189 | # spent 11.0ms (22µs+10.9) within Perl::Critic::Command::_get_input which was called:
# once (22µs+10.9ms) by Perl::Critic::Command::run at line 69 | ||||
190 | |||||
191 | 1 | 900ns | my @args = @_; | ||
192 | |||||
193 | 1 | 900ns | if ( !@args || (@args == 1 && $args[0] eq q{-}) ) { | ||
194 | |||||
195 | # Reading code from STDIN. All the code is slurped into | ||||
196 | # a string. PPI will barf if the string is just whitespace. | ||||
197 | my $code_string = do { local $RS = undef; <STDIN> }; | ||||
198 | |||||
199 | # Notice if STDIN was closed (pipe error, etc) | ||||
200 | if ( ! defined $code_string ) { | ||||
201 | $code_string = $EMPTY; | ||||
202 | } | ||||
203 | |||||
204 | $code_string =~ m{ \S+ }xms || die qq{Nothing to critique.\n}; | ||||
205 | return \$code_string; #Convert to SCALAR ref for PPI | ||||
206 | } | ||||
207 | else { | ||||
208 | |||||
209 | # Test to make sure all the specified files or directories | ||||
210 | # actually exist. If any one of them is bogus, then die. | ||||
211 | 2 | 29µs | 2 | 37µs | if ( my $nonexistent = first { ! -e $_ } @args ) { # spent 23µs making 1 call to List::Util::first
# spent 14µs making 1 call to Perl::Critic::Command::CORE:ftis |
212 | my $msg = qq{No such file or directory: '$nonexistent'}; | ||||
213 | pod2usage( -exitstatus => 1, -message => $msg, -verbose => 0); | ||||
214 | } | ||||
215 | |||||
216 | # Reading code from files or dirs. If argument is a file, | ||||
217 | # then we process it as-is (even though it may not actually | ||||
218 | # be Perl code). If argument is a directory, recursively | ||||
219 | # search the directory for files that look like Perl code. | ||||
220 | 2 | 17µs | 2 | 10.9ms | return map { -d $_ ? Perl::Critic::Utils::all_perl_files($_) : $_ } @args; # spent 10.9ms making 1 call to Perl::Critic::Utils::all_perl_files
# spent 4µs making 1 call to Perl::Critic::Command::CORE:ftdir |
221 | } | ||||
222 | } | ||||
223 | |||||
224 | #------------------------------------------------------------------------------ | ||||
225 | |||||
226 | # spent 34.3s (2.75ms+34.3) within Perl::Critic::Command::_critique which was called:
# once (2.75ms+34.3s) by Perl::Critic::Command::run at line 71 | ||||
227 | |||||
228 | 1 | 22µs | my ( $opts_ref, @files_to_critique ) = @_; | ||
229 | 1 | 200ns | @files_to_critique || die "No perl files were found.\n"; | ||
230 | |||||
231 | # Perl::Critic has lots of dependencies, so loading is delayed | ||||
232 | # until it is really needed. This hack reduces startup time for | ||||
233 | # doing other things like getting the version number or dumping | ||||
234 | # the man page. Arguably, those things are pretty rare, but hey, | ||||
235 | # why not save a few seconds if you can. | ||||
236 | |||||
237 | 1 | 87µs | require Perl::Critic; | ||
238 | 1 | 5µs | 1 | 426ms | $critic = Perl::Critic->new( %{$opts_ref} ); # spent 426ms making 1 call to Perl::Critic::new |
239 | 1 | 3µs | 1 | 15µs | $critic->policies() || die "No policies selected.\n"; # spent 15µs making 1 call to Perl::Critic::policies |
240 | |||||
241 | 1 | 7µs | 3 | 7µs | _set_up_pager($critic->config()->pager()); # spent 3µs making 1 call to Perl::Critic::Command::_set_up_pager
# spent 3µs making 1 call to Perl::Critic::Config::pager
# spent 1µs making 1 call to Perl::Critic::config |
242 | |||||
243 | 1 | 400ns | my $number_of_violations = undef; | ||
244 | 1 | 500ns | my $had_error_in_file = 0; | ||
245 | |||||
246 | 1 | 15µs | for my $file (@files_to_critique) { | ||
247 | |||||
248 | eval { | ||||
249 | 144 | 1.19ms | 288 | 33.4s | my @violations = $critic->critique($file); # spent 32.4s making 144 calls to Perl::Critic::critique, avg 225ms/call
# spent 999ms making 144 calls to PPI::Node::DESTROY, avg 6.94ms/call |
250 | 144 | 85µs | $number_of_violations += scalar @violations; | ||
251 | |||||
252 | 144 | 459µs | 144 | 6.38ms | if (not $opts_ref->{'-statistics-only'}) { # spent 6.38ms making 144 calls to Perl::Critic::Command::_render_report, avg 44µs/call |
253 | _render_report( $file, $opts_ref, @violations ) | ||||
254 | } | ||||
255 | 144 | 125µs | 1; | ||
256 | } | ||||
257 | 144 | 156µs | or do { | ||
258 | if ( my $exception = Perl::Critic::Exception::Parse->caught() ) { | ||||
259 | $had_error_in_file = 1; | ||||
260 | warn qq<Problem while critiquing "$file": $EVAL_ERROR\n>; | ||||
261 | } | ||||
262 | elsif ($EVAL_ERROR) { | ||||
263 | # P::C::Exception::Fatal includes the stack trace in its | ||||
264 | # stringification. | ||||
265 | die qq<Fatal error while critiquing "$file": $EVAL_ERROR\n>; | ||||
266 | } | ||||
267 | else { | ||||
268 | die qq<Fatal error while critiquing "$file". Unfortunately, >, | ||||
269 | q<$@/$EVAL_ERROR >, ## no critic (RequireInterpolationOfMetachars) | ||||
270 | qq<is empty, so the reason can't be shown.\n>; | ||||
271 | } | ||||
272 | } | ||||
273 | } | ||||
274 | |||||
275 | 1 | 1µs | if ( $opts_ref->{-statistics} or $opts_ref->{'-statistics-only'} ) { | ||
276 | my $stats = $critic->statistics(); | ||||
277 | _report_statistics( $opts_ref, $stats ); | ||||
278 | } | ||||
279 | |||||
280 | 1 | 30µs | return $number_of_violations, $had_error_in_file; | ||
281 | } | ||||
282 | |||||
283 | #------------------------------------------------------------------------------ | ||||
284 | |||||
285 | # spent 6.38ms (1.90+4.48) within Perl::Critic::Command::_render_report which was called 144 times, avg 44µs/call:
# 144 times (1.90ms+4.48ms) by Perl::Critic::Command::_critique at line 252, avg 44µs/call | ||||
286 | 144 | 139µs | my ( $file, $opts_ref, @violations ) = @_; | ||
287 | |||||
288 | # Only report the files, if asked. | ||||
289 | 144 | 74µs | my $number_of_violations = scalar @violations; | ||
290 | 144 | 115µs | if ( $opts_ref->{'-files-with-violations'} || | ||
291 | $opts_ref->{'-files-without-violations'} ) { | ||||
292 | not ref $file | ||||
293 | and $opts_ref->{$number_of_violations ? '-files-with-violations' : | ||||
294 | '-files-without-violations'} | ||||
295 | and _out "$file\n"; | ||||
296 | return $number_of_violations; | ||||
297 | } | ||||
298 | |||||
299 | # Only report the number of violations, if asked. | ||||
300 | 144 | 181µs | if( $opts_ref->{-count} ){ | ||
301 | ref $file || _out "$file: "; | ||||
302 | _out "$number_of_violations\n"; | ||||
303 | return $number_of_violations; | ||||
304 | } | ||||
305 | |||||
306 | # Hail all-clear unless we should shut up. | ||||
307 | 144 | 142µs | if( !@violations && !$opts_ref->{-quiet} ) { | ||
308 | 144 | 350µs | 144 | 3.03ms | ref $file || _out "$file "; # spent 3.03ms making 144 calls to Perl::Critic::Command::_out, avg 21µs/call |
309 | 144 | 208µs | 144 | 1.45ms | _out "source OK\n"; # spent 1.45ms making 144 calls to Perl::Critic::Command::_out, avg 10µs/call |
310 | 144 | 421µs | return 0; | ||
311 | } | ||||
312 | |||||
313 | # Otherwise, format and print violations | ||||
314 | my $verbosity = $critic->config->verbose(); | ||||
315 | # $verbosity can be numeric or string, so use "eq" for comparison; | ||||
316 | $verbosity = | ||||
317 | ($verbosity eq $DEFAULT_VERBOSITY && @files > 1) | ||||
318 | ? $DEFAULT_VERBOSITY_WITH_FILE_NAME | ||||
319 | : $verbosity; | ||||
320 | my $fmt = Perl::Critic::Utils::verbosity_to_format( $verbosity ); | ||||
321 | if (not -f $file) { $fmt =~ s< \%[fF] ><STDIN>xms; } #HACK! | ||||
322 | Perl::Critic::Violation::set_format( $fmt ); | ||||
323 | |||||
324 | my $color = $critic->config->color(); | ||||
325 | _out $color ? _colorize_by_severity(@violations) : @violations; | ||||
326 | |||||
327 | return $number_of_violations; | ||||
328 | } | ||||
329 | |||||
330 | #----------------------------------------------------------------------------- | ||||
331 | |||||
332 | # spent 3µs within Perl::Critic::Command::_set_up_pager which was called:
# once (3µs+0s) by Perl::Critic::Command::_critique at line 241 | ||||
333 | 1 | 500ns | my ($pager_command) = @_; | ||
334 | 1 | 3µs | return if not $pager_command; | ||
335 | return if not _at_tty(); | ||||
336 | |||||
337 | open my $pager, q<|->, $pager_command ## no critic (InputOutput::RequireBriefOpen) | ||||
338 | or die qq<Unable to pipe to pager "$pager_command": $ERRNO\n>; | ||||
339 | |||||
340 | $output = $pager; | ||||
341 | |||||
342 | return; | ||||
343 | } | ||||
344 | |||||
345 | #----------------------------------------------------------------------------- | ||||
346 | |||||
347 | sub _report_statistics { | ||||
348 | my ($opts_ref, $statistics) = @_; | ||||
349 | |||||
350 | if ( | ||||
351 | not $opts_ref->{'-statistics-only'} | ||||
352 | and ( | ||||
353 | $statistics->total_violations() | ||||
354 | or not $opts_ref->{-quiet} and $statistics->modules() | ||||
355 | ) | ||||
356 | ) { | ||||
357 | _out "\n"; # There's prior output that we want to separate from. | ||||
358 | } | ||||
359 | |||||
360 | my $files = _commaify($statistics->modules()); | ||||
361 | my $subroutines = _commaify($statistics->subs()); | ||||
362 | my $statements = _commaify($statistics->statements_other_than_subs()); | ||||
363 | my $lines = _commaify($statistics->lines()); | ||||
364 | my $width = max map { length } $files, $subroutines, $statements; | ||||
365 | |||||
366 | _out sprintf "%*s %s.\n", $width, $files, 'files'; | ||||
367 | _out sprintf "%*s %s.\n", $width, $subroutines, 'subroutines/methods'; | ||||
368 | _out sprintf "%*s %s.\n", $width, $statements, 'statements'; | ||||
369 | |||||
370 | my $lines_of_blank = _commaify( $statistics->lines_of_blank() ); | ||||
371 | my $lines_of_comment = _commaify( $statistics->lines_of_comment() ); | ||||
372 | my $lines_of_data = _commaify( $statistics->lines_of_data() ); | ||||
373 | my $lines_of_perl = _commaify( $statistics->lines_of_perl() ); | ||||
374 | my $lines_of_pod = _commaify( $statistics->lines_of_pod() ); | ||||
375 | |||||
376 | $width = | ||||
377 | max map { length } | ||||
378 | $lines_of_blank, $lines_of_comment, $lines_of_data, | ||||
379 | $lines_of_perl, $lines_of_pod; | ||||
380 | _out sprintf "\n%s %s:\n", $lines, 'lines, consisting of'; | ||||
381 | _out sprintf " %*s %s.\n", $width, $lines_of_blank, 'blank lines'; | ||||
382 | _out sprintf " %*s %s.\n", $width, $lines_of_comment, 'comment lines'; | ||||
383 | _out sprintf " %*s %s.\n", $width, $lines_of_data, 'data lines'; | ||||
384 | _out sprintf " %*s %s.\n", $width, $lines_of_perl, 'lines of Perl code'; | ||||
385 | _out sprintf " %*s %s.\n", $width, $lines_of_pod, 'lines of POD'; | ||||
386 | |||||
387 | my $average_sub_mccabe = $statistics->average_sub_mccabe(); | ||||
388 | if (defined $average_sub_mccabe) { | ||||
389 | _out | ||||
390 | sprintf | ||||
391 | "\nAverage McCabe score of subroutines was %.2f.\n", | ||||
392 | $average_sub_mccabe; | ||||
393 | } | ||||
394 | |||||
395 | _out "\n"; | ||||
396 | |||||
397 | _out _commaify($statistics->total_violations()), " violations.\n"; | ||||
398 | |||||
399 | my $violations_per_file = $statistics->violations_per_file(); | ||||
400 | if (defined $violations_per_file) { | ||||
401 | _out | ||||
402 | sprintf | ||||
403 | "Violations per file was %.3f.\n", | ||||
404 | $violations_per_file; | ||||
405 | } | ||||
406 | my $violations_per_statement = $statistics->violations_per_statement(); | ||||
407 | if (defined $violations_per_statement) { | ||||
408 | _out | ||||
409 | sprintf | ||||
410 | "Violations per statement was %.3f.\n", | ||||
411 | $violations_per_statement; | ||||
412 | } | ||||
413 | my $violations_per_line = $statistics->violations_per_line_of_code(); | ||||
414 | if (defined $violations_per_line) { | ||||
415 | _out | ||||
416 | sprintf | ||||
417 | "Violations per line of code was %.3f.\n", | ||||
418 | $violations_per_line; | ||||
419 | } | ||||
420 | |||||
421 | if ( $statistics->total_violations() ) { | ||||
422 | _out "\n"; | ||||
423 | |||||
424 | my %severity_violations = %{ $statistics->violations_by_severity() }; | ||||
425 | my @severities = reverse sort keys %severity_violations; | ||||
426 | $width = | ||||
427 | max | ||||
428 | map { length _commaify( $severity_violations{$_} ) } | ||||
429 | @severities; | ||||
430 | foreach my $severity (@severities) { | ||||
431 | _out | ||||
432 | sprintf | ||||
433 | "%*s severity %d violations.\n", | ||||
434 | $width, | ||||
435 | _commaify( $severity_violations{$severity} ), | ||||
436 | $severity; | ||||
437 | } | ||||
438 | |||||
439 | _out "\n"; | ||||
440 | |||||
441 | my %policy_violations = %{ $statistics->violations_by_policy() }; | ||||
442 | my @policies = sort keys %policy_violations; | ||||
443 | $width = | ||||
444 | max | ||||
445 | map { length _commaify( $policy_violations{$_} ) } | ||||
446 | @policies; | ||||
447 | foreach my $policy (@policies) { | ||||
448 | _out | ||||
449 | sprintf | ||||
450 | "%*s violations of %s.\n", | ||||
451 | $width, | ||||
452 | _commaify($policy_violations{$policy}), | ||||
453 | policy_short_name($policy); | ||||
454 | } | ||||
455 | } | ||||
456 | |||||
457 | return; | ||||
458 | } | ||||
459 | |||||
460 | #----------------------------------------------------------------------------- | ||||
461 | |||||
462 | # Only works for integers. | ||||
463 | sub _commaify { | ||||
464 | my ( $number ) = @_; | ||||
465 | |||||
466 | while ($number =~ s/ \A ( [-+]? \d+ ) ( \d{3} ) /$1,$2/xms) { | ||||
467 | # nothing | ||||
468 | } | ||||
469 | |||||
470 | return $number; | ||||
471 | } | ||||
472 | |||||
473 | #----------------------------------------------------------------------------- | ||||
474 | |||||
475 | # spent 10µs within Perl::Critic::Command::_get_option_specification which was called:
# once (10µs+0s) by Perl::Critic::Command::_parse_command_line at line 117 | ||||
476 | |||||
477 | 1 | 16µs | return qw< | ||
478 | 5 4 3 2 1 | ||||
479 | Safari | ||||
480 | version | ||||
481 | brutal | ||||
482 | count|C | ||||
483 | cruel | ||||
484 | doc=s | ||||
485 | exclude=s@ | ||||
486 | force! | ||||
487 | gentle | ||||
488 | harsh | ||||
489 | help|?|H | ||||
490 | include=s@ | ||||
491 | list | ||||
492 | list-enabled | ||||
493 | list-themes | ||||
494 | man | ||||
495 | color|colour! | ||||
496 | noprofile | ||||
497 | only! | ||||
498 | options | ||||
499 | pager=s | ||||
500 | profile|p=s | ||||
501 | profile-proto | ||||
502 | quiet | ||||
503 | severity=i | ||||
504 | single-policy|s=s | ||||
505 | stern | ||||
506 | statistics! | ||||
507 | statistics-only! | ||||
508 | profile-strictness=s | ||||
509 | theme=s | ||||
510 | top:i | ||||
511 | allow-unsafe | ||||
512 | verbose=s | ||||
513 | color-severity-highest|colour-severity-highest|color-severity-5|colour-severity-5=s | ||||
514 | color-severity-high|colour-severity-high|color-severity-4|colour-severity-4=s | ||||
515 | color-severity-medium|colour-severity-medium|color-severity-3|colour-severity-3=s | ||||
516 | color-severity-low|colour-severity-low|color-severity-2|colour-severity-2=s | ||||
517 | color-severity-lowest|colour-severity-lowest|color-severity-1|colour-severity-1=s | ||||
518 | files-with-violations|l | ||||
519 | files-without-violations|L | ||||
520 | program-extensions=s@ | ||||
521 | >; | ||||
522 | } | ||||
523 | |||||
524 | #----------------------------------------------------------------------------- | ||||
525 | |||||
526 | sub _colorize_by_severity { | ||||
527 | my @violations = @_; | ||||
528 | return @violations if _this_is_windows(); | ||||
529 | return @violations if not eval { | ||||
530 | require Term::ANSIColor; | ||||
531 | Term::ANSIColor->VERSION( $_MODULE_VERSION_TERM_ANSICOLOR ); | ||||
532 | 1; | ||||
533 | }; | ||||
534 | |||||
535 | my $config = $critic->config(); | ||||
536 | my %color_of = ( | ||||
537 | $SEVERITY_HIGHEST => $config->color_severity_highest(), | ||||
538 | $SEVERITY_HIGH => $config->color_severity_high(), | ||||
539 | $SEVERITY_MEDIUM => $config->color_severity_medium(), | ||||
540 | $SEVERITY_LOW => $config->color_severity_low(), | ||||
541 | $SEVERITY_LOWEST => $config->color_severity_lowest(), | ||||
542 | ); | ||||
543 | |||||
544 | return map { _colorize( "$_", $color_of{$_->severity()} ) } @violations; | ||||
545 | |||||
546 | } | ||||
547 | |||||
548 | #----------------------------------------------------------------------------- | ||||
549 | |||||
550 | sub _colorize { | ||||
551 | my ($string, $color) = @_; | ||||
552 | return $string if not defined $color; | ||||
553 | return $string if $color eq $EMPTY; | ||||
554 | # $terminator is a purely cosmetic change to make the color end at the end | ||||
555 | # of the line rather than right before the next line. It is here because | ||||
556 | # if you use background colors, some console windows display a little | ||||
557 | # fragment of colored background before the next uncolored (or | ||||
558 | # differently-colored) line. | ||||
559 | my $terminator = chomp $string ? "\n" : $EMPTY; | ||||
560 | return Term::ANSIColor::colored( $string, $color ) . $terminator; | ||||
561 | } | ||||
562 | |||||
563 | #----------------------------------------------------------------------------- | ||||
564 | |||||
565 | sub _this_is_windows { | ||||
566 | return 1 if $OSNAME =~ m/MSWin32/xms; | ||||
567 | return 0; | ||||
568 | } | ||||
569 | |||||
570 | #----------------------------------------------------------------------------- | ||||
571 | |||||
572 | sub _at_tty { | ||||
573 | return -t STDOUT; ## no critic (ProhibitInteractiveTest); | ||||
574 | } | ||||
575 | |||||
576 | #----------------------------------------------------------------------------- | ||||
577 | |||||
578 | sub _render_all_policy_listing { | ||||
579 | # Force P-C parameters, to catch all Policies on this site | ||||
580 | my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST); | ||||
581 | return _render_policy_listing( %pc_params ); | ||||
582 | } | ||||
583 | |||||
584 | #----------------------------------------------------------------------------- | ||||
585 | |||||
586 | sub _render_policy_listing { | ||||
587 | my %pc_params = @_; | ||||
588 | |||||
589 | require Perl::Critic::PolicyListing; | ||||
590 | require Perl::Critic; | ||||
591 | |||||
592 | my @policies = Perl::Critic->new( %pc_params )->policies(); | ||||
593 | my $listing = Perl::Critic::PolicyListing->new( -policies => \@policies ); | ||||
594 | _out $listing; | ||||
595 | |||||
596 | exit $EXIT_SUCCESS; | ||||
597 | } | ||||
598 | |||||
599 | #----------------------------------------------------------------------------- | ||||
600 | |||||
601 | sub _render_theme_listing { | ||||
602 | |||||
603 | require Perl::Critic::ThemeListing; | ||||
604 | require Perl::Critic; | ||||
605 | |||||
606 | my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST); | ||||
607 | my @policies = Perl::Critic->new( %pc_params )->policies(); | ||||
608 | my $listing = Perl::Critic::ThemeListing->new( -policies => \@policies ); | ||||
609 | _out $listing; | ||||
610 | |||||
611 | exit $EXIT_SUCCESS; | ||||
612 | } | ||||
613 | |||||
614 | #----------------------------------------------------------------------------- | ||||
615 | |||||
616 | sub _render_profile_prototype { | ||||
617 | |||||
618 | require Perl::Critic::ProfilePrototype; | ||||
619 | require Perl::Critic; | ||||
620 | |||||
621 | my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST); | ||||
622 | my @policies = Perl::Critic->new( %pc_params )->policies(); | ||||
623 | my $prototype = Perl::Critic::ProfilePrototype->new( -policies => \@policies ); | ||||
624 | _out $prototype; | ||||
625 | |||||
626 | exit $EXIT_SUCCESS; | ||||
627 | } | ||||
628 | |||||
629 | #----------------------------------------------------------------------------- | ||||
630 | |||||
631 | sub _render_policy_docs { | ||||
632 | |||||
633 | my (%opts) = @_; | ||||
634 | my $pattern = delete $opts{-doc}; | ||||
635 | |||||
636 | require Perl::Critic; | ||||
637 | $critic = Perl::Critic->new(%opts); | ||||
638 | _set_up_pager($critic->config()->pager()); | ||||
639 | |||||
640 | require Perl::Critic::PolicyFactory; | ||||
641 | my @site_policies = Perl::Critic::PolicyFactory->site_policy_names(); | ||||
642 | my @matching_policies = grep { $_ =~ m/$pattern/ixms } @site_policies; | ||||
643 | |||||
644 | # "-T" means don't send to pager | ||||
645 | my @perldoc_output = map {`perldoc -T $_`} @matching_policies; ## no critic (ProhibitBacktick) | ||||
646 | _out @perldoc_output; | ||||
647 | |||||
648 | exit $EXIT_SUCCESS; | ||||
649 | } | ||||
650 | |||||
651 | #----------------------------------------------------------------------------- | ||||
652 | |||||
653 | sub _display_version { | ||||
654 | _out "$VERSION\n"; | ||||
655 | exit $EXIT_SUCCESS; | ||||
656 | } | ||||
657 | |||||
658 | #----------------------------------------------------------------------------- | ||||
659 | 1 | 8µs | 1; | ||
660 | |||||
661 | __END__ | ||||
# spent 4µs within Perl::Critic::Command::CORE:ftdir which was called:
# once (4µs+0s) by Perl::Critic::Command::_get_input at line 220 | |||||
# spent 14µs within Perl::Critic::Command::CORE:ftis which was called:
# once (14µs+0s) by List::Util::first at line 211 | |||||
# spent 2.43ms within Perl::Critic::Command::CORE:print which was called 288 times, avg 8µs/call:
# 288 times (2.43ms+0s) by Perl::Critic::Command::_out at line 62, avg 8µs/call |