Login
Tweak to P:C::Utils::is_class_name to filter out chained method calls, such as:
[gknop/Perl-Critic.git] / lib / Perl / Critic / Utils.pm
CommitLineData
6036a254 1##############################################################################
39cd321a
JRT
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6036a254 6##############################################################################
39cd321a 7
59b05e08
JRT
8package Perl::Critic::Utils;
9
10use strict;
11use warnings;
c948abe5 12
0bcb38c0 13use Carp qw(confess);
410cf90b 14use File::Spec qw();
c948abe5 15use Scalar::Util qw( blessed );
e2d4c0f0 16use B::Keywords qw();
c948abe5 17
59b05e08
JRT
18use base 'Exporter';
19
37915b13 20our $VERSION = 1.051;
59b05e08 21
6036a254 22#-----------------------------------------------------------------------------
bbf4108c 23# Exportable symbols here.
1fe8e187 24
bbf4108c 25our @EXPORT_OK = qw(
dc93df4f
JRT
26 $TRUE
27 $FALSE
28
e2d4c0f0
JRT
29 $POLICY_NAMESPACE
30
dc93df4f
JRT
31 $SEVERITY_HIGHEST
32 $SEVERITY_HIGH
33 $SEVERITY_MEDIUM
34 $SEVERITY_LOW
35 $SEVERITY_LOWEST
0bcb38c0 36 @SEVERITY_NAMES
dc93df4f
JRT
37
38 $COLON
39 $COMMA
40 $DQUOTE
41 $EMPTY
42 $FATCOMMA
43 $PERIOD
44 $PIPE
45 $QUOTE
46 $SCOLON
47 $SPACE
a609ec83
ES
48 $SLASH
49 $BSLASH
310e7cf9
ES
50 $LEFT_PAREN
51 $RIGHT_PAREN
6f31806e 52
dc93df4f
JRT
53 &all_perl_files
54 &find_keywords
bbf4108c 55 &first_arg
dc93df4f 56 &hashify
7b84ff16 57 &interpolate
f7a00b57 58 &is_class_name
dc93df4f 59 &is_function_call
6f31806e 60 &is_hash_key
0893757b 61 &is_included_module_name
aa0d7c6e 62 &is_label_pointer
dc93df4f 63 &is_method_call
bdaf4dac 64 &is_package_declaration
6f31806e 65 &is_perl_builtin
3ca95ec9 66 &is_perl_bareword
c948abe5
ES
67 &is_perl_builtin_with_list_context
68 &is_perl_builtin_with_multiple_arguments
27ac78c7
ES
69 &is_perl_builtin_with_no_arguments
70 &is_perl_builtin_with_one_argument
71 &is_perl_builtin_with_optional_argument
72 &is_perl_builtin_with_zero_and_or_one_arguments
2c30044d 73 &is_perl_filehandle
6f31806e 74 &is_perl_global
ee3a2f51 75 &is_qualified_name
dc93df4f 76 &is_script
6f31806e 77 &is_subroutine_name
bbf4108c 78 &is_unchecked_call
6f31806e 79 &parse_arg_list
dc93df4f
JRT
80 &policy_long_name
81 &policy_short_name
6f31806e 82 &precedence_of
0bcb38c0 83 &severity_to_number
bbf4108c 84 &shebang_line
dc93df4f 85 &verbosity_to_format
4a7a7227 86 &words_from_string
bbf4108c
ES
87);
88
7cb05702
JRT
89
90# Note: this is deprecated.
91our @EXPORT = @EXPORT_OK; ## no critic (ProhibitAutomaticExport)
92
5feaec1d 93
bbf4108c
ES
94our %EXPORT_TAGS = (
95 all => [ @EXPORT_OK ],
96 booleans => [ qw{ $TRUE $FALSE } ],
97 severities => [
98 qw{
99 $SEVERITY_HIGHEST
100 $SEVERITY_HIGH
101 $SEVERITY_MEDIUM
102 $SEVERITY_LOW
103 $SEVERITY_LOWEST
104 @SEVERITY_NAMES
105 }
106 ],
107 characters => [
108 qw{
109 $COLON
110 $COMMA
111 $DQUOTE
112 $EMPTY
113 $FATCOMMA
114 $PERIOD
115 $PIPE
116 $QUOTE
117 $SCOLON
118 $SPACE
119 $SLASH
120 $BSLASH
310e7cf9
ES
121 $LEFT_PAREN
122 $RIGHT_PAREN
bbf4108c
ES
123 }
124 ],
125 classification => [
126 qw{
f7a00b57 127 &is_class_name
bbf4108c
ES
128 &is_function_call
129 &is_hash_key
0893757b 130 &is_included_module_name
aa0d7c6e 131 &is_label_pointer
bbf4108c 132 &is_method_call
bdaf4dac 133 &is_package_declaration
2c30044d 134 &is_perl_bareword
bbf4108c 135 &is_perl_builtin
2c30044d 136 &is_perl_filehandle
bbf4108c 137 &is_perl_global
c948abe5
ES
138 &is_perl_builtin_with_list_context
139 &is_perl_builtin_with_multiple_arguments
27ac78c7
ES
140 &is_perl_builtin_with_no_arguments
141 &is_perl_builtin_with_one_argument
142 &is_perl_builtin_with_optional_argument
143 &is_perl_builtin_with_zero_and_or_one_arguments
ee3a2f51 144 &is_qualified_name
bbf4108c
ES
145 &is_script
146 &is_subroutine_name
147 &is_unchecked_call
148 }
149 ],
150 data_conversion => [ qw{ &hashify &words_from_string &interpolate } ],
151 ppi => [ qw{ &first_arg &parse_arg_list } ],
152 internal_lookup => [ qw{ &severity_to_number &verbosity_to_format } ],
153 language => [ qw{ &precedence_of } ],
154 deprecated => [ qw{ &find_keywords } ],
59b05e08
JRT
155);
156
6036a254 157#-----------------------------------------------------------------------------
59b05e08 158
1fe8e187
JRT
159our $POLICY_NAMESPACE = 'Perl::Critic::Policy';
160
6036a254 161#-----------------------------------------------------------------------------
1fe8e187 162
7e86d49a
JRT
163our $SEVERITY_HIGHEST = 5;
164our $SEVERITY_HIGH = 4;
165our $SEVERITY_MEDIUM = 3;
166our $SEVERITY_LOW = 2;
167our $SEVERITY_LOWEST = 1;
dff08b70 168
6036a254 169#-----------------------------------------------------------------------------
6b4a61e9 170
310e7cf9
ES
171our $COMMA = q{,};
172our $FATCOMMA = q{=>};
173our $COLON = q{:};
174our $SCOLON = q{;};
175our $QUOTE = q{'};
176our $DQUOTE = q{"};
177our $PERIOD = q{.};
178our $PIPE = q{|};
179our $SPACE = q{ };
180our $SLASH = q{/};
181our $BSLASH = q{\\};
182our $LEFT_PAREN = q{(};
183our $RIGHT_PAREN = q{)};
184our $EMPTY = q{};
185our $TRUE = 1;
186our $FALSE = 0;
59b05e08 187
6036a254 188#-----------------------------------------------------------------------------
6b4a61e9 189
8d6b89b3
JRT
190#TODO: Should this include punctuations vars?
191
59b05e08 192
8d6b89b3 193
6036a254 194#-----------------------------------------------------------------------------
dc93df4f 195## no critic (ProhibitNoisyQuotes);
57973330 196
8d6b89b3 197my %PRECEDENCE_OF = (
d0dd0a1a
JRT
198 '->' => 1, '<' => 10, '//' => 15, '.=' => 19,
199 '++' => 2, '>' => 10, '||' => 15, '^=' => 19,
200 '--' => 2, '<=' => 10, '..' => 16, '<<=' => 19,
201 '**' => 3, '>=' => 10, '...' => 17, '>>=' => 19,
202 '!' => 4, 'lt' => 10, '?' => 18, ',' => 20,
203 '~' => 4, 'gt' => 10, ':' => 18, '=>' => 20,
204 '\\' => 4, 'le' => 10, '=' => 19, 'not' => 22,
205 '=~' => 5, 'ge' => 10, '+=' => 19, 'and' => 23,
206 '!~' => 5, '==' => 11, '-=' => 19, 'or' => 24,
207 '*' => 6, '!=' => 11, '*=' => 19, 'xor' => 24,
208 '/' => 6, '<=>' => 11, '/=' => 19,
209 '%' => 6, 'eq' => 11, '%=' => 19,
210 'x' => 6, 'ne' => 11, '||=' => 19,
211 '+' => 7, 'cmp' => 11, '&&=' => 19,
212 '-' => 7, '&' => 12, '|=' => 19,
213 '.' => 7, '|' => 13, '&=' => 19,
214 '<<' => 8, '^' => 13, '**=' => 19,
215 '>>' => 8, '&&' => 14, 'x=' => 19,
8d6b89b3
JRT
216);
217
57973330 218## use critic
7b84ff16 219#-----------------------------------------------------------------------------
8d6b89b3 220
3ffdaa3b
AL
221sub hashify {
222 return map { $_ => 1 } @_;
223}
224
7b84ff16
JRT
225#-----------------------------------------------------------------------------
226
227sub interpolate {
228 my ( $literal ) = @_;
229 return eval "\"$literal\""; ## no critic 'StringyEval';
230}
231
232#-----------------------------------------------------------------------------
3ffdaa3b 233
59b05e08
JRT
234sub find_keywords {
235 my ( $doc, $keyword ) = @_;
45acb16b
CD
236 my $nodes_ref = $doc->find('PPI::Token::Word');
237 return if !$nodes_ref;
59b05e08
JRT
238 my @matches = grep { $_ eq $keyword } @{$nodes_ref};
239 return @matches ? \@matches : undef;
240}
241
7b84ff16 242#-----------------------------------------------------------------------------
c948abe5
ES
243
244sub _name_for_sub_or_stringified_element {
245 my $elem = shift;
246
247 if ( blessed $elem and $elem->isa('PPI::Statement::Sub') ) {
248 return $elem->name();
249 }
250
251 return "$elem";
252}
253
254#-----------------------------------------------------------------------------
207c8eb0 255## no critic (ProhibitPackageVars)
dff08b70 256
e2d4c0f0
JRT
257my %BUILTINS = hashify( @B::Keywords::Functions );
258
8d6b89b3 259sub is_perl_builtin {
45acb16b
CD
260 my $elem = shift;
261 return if !$elem;
c948abe5
ES
262
263 return exists $BUILTINS{ _name_for_sub_or_stringified_element($elem) };
8d6b89b3 264}
36f7994c 265
7b84ff16 266#-----------------------------------------------------------------------------
8d6b89b3 267
3ca95ec9
JRT
268my %BAREWORDS = hashify( @B::Keywords::Barewords );
269
270sub is_perl_bareword {
271 my $elem = shift;
272 return if !$elem;
273
274 return exists $BAREWORDS{ _name_for_sub_or_stringified_element($elem) };
275}
276
277#-----------------------------------------------------------------------------
278
207c8eb0 279my @GLOBALS_WITHOUT_SIGILS = map { substr $_, 1 } @B::Keywords::Arrays,
e2d4c0f0
JRT
280 @B::Keywords::Hashes,
281 @B::Keywords::Scalars;
282
283my %GLOBALS= hashify( @GLOBALS_WITHOUT_SIGILS );
284
8d6b89b3 285sub is_perl_global {
45acb16b
CD
286 my $elem = shift;
287 return if !$elem;
3c71d40c
JRT
288 my $var_name = "$elem"; #Convert Token::Symbol to string
289 $var_name =~ s{\A [\$@%] }{}mx; #Chop off the sigil
290 return exists $GLOBALS{ $var_name };
8d6b89b3
JRT
291}
292
2c30044d
JRT
293#-----------------------------------------------------------------------------
294
295my %FILEHANDLES = hashify( @B::Keywords::Filehandles );
296
297sub is_perl_filehandle {
298 my $elem = shift;
299 return if !$elem;
300
301 return exists $FILEHANDLES{ _name_for_sub_or_stringified_element($elem) };
302}
303
207c8eb0 304## use critic
7b84ff16 305#-----------------------------------------------------------------------------
8d6b89b3 306
c948abe5
ES
307# egrep '=item.*LIST' perlfunc.pod
308my %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT =
309 hashify(
310 qw{
311 chmod
312 chown
313 die
314 exec
315 formline
316 grep
317 import
318 join
319 kill
320 map
321 no
322 open
323 pack
324 print
325 printf
326 push
327 reverse
19d26f4f 328 say
c948abe5
ES
329 sort
330 splice
331 sprintf
332 syscall
333 system
334 tie
335 unlink
336 unshift
337 use
338 utime
339 warn
27ac78c7 340 },
c948abe5
ES
341 );
342
343sub is_perl_builtin_with_list_context {
344 my $elem = shift;
345
346 return
347 exists
348 $BUILTINS_WHICH_PROVIDE_LIST_CONTEXT{
349 _name_for_sub_or_stringified_element($elem)
350 };
351}
352
353#-----------------------------------------------------------------------------
354
355# egrep '=item.*[A-Z],' perlfunc.pod
356my %BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS =
357 hashify(
358 qw{
359 accept
360 atan2
361 bind
362 binmode
363 bless
364 connect
365 crypt
366 dbmopen
367 fcntl
368 flock
369 gethostbyaddr
370 getnetbyaddr
371 getpriority
372 getservbyname
373 getservbyport
374 getsockopt
375 index
376 ioctl
377 link
378 listen
379 mkdir
380 msgctl
381 msgget
382 msgrcv
383 msgsnd
384 open
385 opendir
386 pipe
387 read
388 recv
389 rename
390 rindex
391 seek
392 seekdir
393 select
394 semctl
395 semget
396 semop
397 send
398 setpgrp
399 setpriority
400 setsockopt
401 shmctl
402 shmget
403 shmread
404 shmwrite
405 shutdown
406 socket
407 socketpair
408 splice
409 split
410 substr
411 symlink
412 sysopen
413 sysread
414 sysseek
415 syswrite
416 truncate
417 unpack
418 vec
419 waitpid
420 },
421 keys %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT
422 );
423
424sub is_perl_builtin_with_multiple_arguments {
425 my $elem = shift;
426
427 return
428 exists
429 $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{
430 _name_for_sub_or_stringified_element($elem)
431 };
432}
433
434#-----------------------------------------------------------------------------
435
27ac78c7
ES
436my %BUILTINS_WHICH_TAKE_NO_ARGUMENTS =
437 hashify(
438 qw{
439 endgrent
440 endhostent
441 endnetent
442 endprotoent
443 endpwent
444 endservent
445 fork
446 format
447 getgrent
448 gethostent
449 getlogin
450 getnetent
451 getppid
452 getprotoent
453 getpwent
454 getservent
455 setgrent
456 setpwent
457 split
458 time
459 times
460 wait
461 wantarray
462 }
463 );
464
465sub is_perl_builtin_with_no_arguments {
466 my $elem = shift;
467
468 return
469 exists
470 $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{
471 _name_for_sub_or_stringified_element($elem)
472 };
473}
474
475#-----------------------------------------------------------------------------
476
477my %BUILTINS_WHICH_TAKE_ONE_ARGUMENT =
478 hashify(
479 qw{
480 closedir
481 dbmclose
482 delete
483 each
484 exists
485 fileno
486 getgrgid
487 getgrnam
488 gethostbyname
489 getnetbyname
490 getpeername
491 getpgrp
492 getprotobyname
493 getprotobynumber
494 getpwnam
495 getpwuid
496 getsockname
497 goto
498 keys
499 local
500 prototype
501 readdir
502 readline
503 readpipe
504 rewinddir
505 scalar
506 sethostent
507 setnetent
508 setprotoent
509 setservent
510 telldir
511 tied
512 untie
513 values
514 }
515 );
516
517sub is_perl_builtin_with_one_argument {
518 my $elem = shift;
519
520 return
521 exists
522 $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{
523 _name_for_sub_or_stringified_element($elem)
524 };
525}
526
527#-----------------------------------------------------------------------------
528
529## no critic (ProhibitPackageVars)
530my %BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT =
531 hashify(
532 grep { not exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $_ } }
533 grep { not exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $_ } }
534 grep { not exists $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ $_ } }
535 @B::Keywords::Functions
536 );
537## use critic
538
539sub is_perl_builtin_with_optional_argument {
540 my $elem = shift;
541
542 return
543 exists
544 $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{
545 _name_for_sub_or_stringified_element($elem)
546 };
547}
548
549#-----------------------------------------------------------------------------
550
551sub is_perl_builtin_with_zero_and_or_one_arguments {
552 my $elem = shift;
8e2aefdb 553
27ac78c7
ES
554 return if not $elem;
555
556 my $name = _name_for_sub_or_stringified_element($elem);
557
558 return (
559 exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $name }
560 or exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $name }
561 or exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ $name }
562 );
563}
564
565#-----------------------------------------------------------------------------
566
ee3a2f51
ES
567sub is_qualified_name {
568 my $name = shift;
569
570 return if not $name;
571
572 return index ( $name, q{::} ) >= 0;
573}
574
575#-----------------------------------------------------------------------------
576
8d6b89b3 577sub precedence_of {
45acb16b
CD
578 my $elem = shift;
579 return if !$elem;
3c71d40c 580 return $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem };
8d6b89b3
JRT
581}
582
7b84ff16 583#-----------------------------------------------------------------------------
8d6b89b3 584
59b05e08
JRT
585sub is_hash_key {
586 my $elem = shift;
45acb16b 587 return if !$elem;
59b05e08
JRT
588
589 #Check curly-brace style: $hash{foo} = bar;
45acb16b
CD
590 my $parent = $elem->parent();
591 return if !$parent;
592 my $grandparent = $parent->parent();
593 return if !$grandparent;
59b05e08
JRT
594 return 1 if $grandparent->isa('PPI::Structure::Subscript');
595
596
597 #Check declarative style: %hash = (foo => bar);
45acb16b
CD
598 my $sib = $elem->snext_sibling();
599 return if !$sib;
59b05e08
JRT
600 return 1 if $sib->isa('PPI::Token::Operator') && $sib eq '=>';
601
45acb16b 602 return;
59b05e08
JRT
603}
604
7b84ff16 605#-----------------------------------------------------------------------------
dff08b70 606
0893757b
ES
607sub is_included_module_name {
608 my $elem = shift;
609 return if !$elem;
610 my $stmnt = $elem->statement();
611 return if !$stmnt;
612 return if !$stmnt->isa('PPI::Statement::Include');
613 return $stmnt->schild(1) == $elem;
614}
615
616#-----------------------------------------------------------------------------
617
aa0d7c6e
JRT
618sub is_label_pointer {
619 my $elem = shift;
620 return if !$elem;
621
622 my $statement = $elem->statement();
623 return if !$statement;
624
625 my $psib = $elem->sprevious_sibling();
626 return if !$psib;
627
628 return $statement->isa('PPI::Statement::Break')
629 && $psib =~ m/(?:redo|goto|next|last)/mxo;
630}
631
632#-----------------------------------------------------------------------------
633
59b05e08
JRT
634sub is_method_call {
635 my $elem = shift;
45acb16b 636 return if !$elem;
8053d374 637
f7a00b57
JRT
638 return _is_dereference_operator( $elem->sprevious_sibling() );
639}
640
641#-----------------------------------------------------------------------------
642
643sub is_class_name {
644 my $elem = shift;
645 return if !$elem;
646
334c45ee
JRT
647 return _is_dereference_operator( $elem->snext_sibling() )
648 && !_is_dereference_operator( $elem->sprevious_sibling() );
8053d374
JRT
649}
650
651#-----------------------------------------------------------------------------
652
653sub _is_dereference_operator {
654 my $elem = shift;
655 return if !$elem;
656
657 return $elem->isa('PPI::Token::Operator') && $elem eq q{->};
59b05e08
JRT
658}
659
7b84ff16 660#-----------------------------------------------------------------------------
dff08b70 661
bdaf4dac
ES
662sub is_package_declaration {
663 my $elem = shift;
664 return if !$elem;
665 my $stmnt = $elem->statement();
666 return if !$stmnt;
667 return if !$stmnt->isa('PPI::Statement::Package');
668 return $stmnt->schild(1) == $elem;
669}
670
671#-----------------------------------------------------------------------------
672
0c377685
JRT
673sub is_subroutine_name {
674 my $elem = shift;
45acb16b
CD
675 return if !$elem;
676 my $sib = $elem->sprevious_sibling();
677 return if !$sib;
678 my $stmnt = $elem->statement();
679 return if !$stmnt;
0c377685
JRT
680 return $stmnt->isa('PPI::Statement::Sub') && $sib eq 'sub';
681}
682
7b84ff16 683#-----------------------------------------------------------------------------
0c377685 684
dc118d1b
JRT
685sub is_function_call {
686 my $elem = shift;
3ca95ec9
JRT
687 return if ! $elem;
688
689 return if is_hash_key($elem);
690 return if is_method_call($elem);
f7a00b57 691 return if is_class_name($elem);
3ca95ec9
JRT
692 return if is_subroutine_name($elem);
693 return if is_included_module_name($elem);
694 return if is_package_declaration($elem);
695 return if is_perl_bareword($elem);
2c30044d 696 return if is_perl_filehandle($elem);
aa0d7c6e 697 return if is_label_pointer($elem);
3ca95ec9
JRT
698
699 return 1;
dc118d1b
JRT
700}
701
7b84ff16 702#-----------------------------------------------------------------------------
dc118d1b 703
dff08b70
JRT
704sub is_script {
705 my $doc = shift;
e992086d
AL
706
707 return shebang_line($doc) ? 1 : 0;
dff08b70
JRT
708}
709
7b84ff16 710#-----------------------------------------------------------------------------
dff08b70 711
dc93df4f 712sub policy_long_name {
1fe8e187
JRT
713 my ( $policy_name ) = @_;
714 if ( $policy_name !~ m{ \A $POLICY_NAMESPACE }mx ) {
715 $policy_name = $POLICY_NAMESPACE . q{::} . $policy_name;
dc93df4f
JRT
716 }
717 return $policy_name;
718}
719
7b84ff16 720#-----------------------------------------------------------------------------
dc93df4f
JRT
721
722sub policy_short_name {
1fe8e187
JRT
723 my ( $policy_name ) = @_;
724 $policy_name =~ s{\A $POLICY_NAMESPACE ::}{}mx;
dc93df4f
JRT
725 return $policy_name;
726}
727
7b84ff16 728#-----------------------------------------------------------------------------
dc93df4f 729
14a6a3ef
CD
730sub first_arg {
731 my $elem = shift;
732 my $sib = $elem->snext_sibling();
733 return if !$sib;
734
735 if ( $sib->isa('PPI::Structure::List') ) {
736
737 my $expr = $sib->schild(0);
738 return if !$expr;
739 return $expr->isa('PPI::Statement') ? $expr->schild(0) : $expr;
740 }
741
742 return $sib;
743}
744
745#-----------------------------------------------------------------------------
746
59b05e08
JRT
747sub parse_arg_list {
748 my $elem = shift;
45acb16b
CD
749 my $sib = $elem->snext_sibling();
750 return if !$sib;
59b05e08
JRT
751
752 if ( $sib->isa('PPI::Structure::List') ) {
753
0a6f07d0 754 #Pull siblings from list
45acb16b
CD
755 my $expr = $sib->schild(0);
756 return if !$expr;
0a6f07d0 757 return _split_nodes_on_comma( $expr->schildren() );
59b05e08
JRT
758 }
759 else {
760
0a6f07d0
AL
761 #Gather up remaining nodes in the statement
762 my $iter = $elem;
763 my @arg_list = ();
59b05e08 764
0a6f07d0
AL
765 while ($iter = $iter->snext_sibling() ) {
766 last if $iter->isa('PPI::Token::Structure') and $iter eq $SCOLON;
767 push @arg_list, $iter;
768 }
769 return _split_nodes_on_comma( @arg_list );
59b05e08
JRT
770 }
771}
772
dff08b70
JRT
773#---------------------------------
774
59b05e08
JRT
775sub _split_nodes_on_comma {
776 my @nodes = ();
777 my $i = 0;
778 for my $node (@_) {
6f31806e
AL
779 if ( $node->isa('PPI::Token::Operator') &&
780 (($node eq $COMMA) || ($node eq $FATCOMMA)) ) {
0a6f07d0
AL
781 $i++; #Move forward to next 'node stack'
782 next;
783 }
40ec8029 784 push @{ $nodes[$i] }, $node;
59b05e08
JRT
785 }
786 return @nodes;
787}
bf159007 788
8645eb2c
JRT
789#-----------------------------------------------------------------------------
790
23952868
JJ
791# XXX: You must keep the regular expressions in extras/perlcritic.el in sync
792# if you change these.
4268e673
JRT
793my %FORMAT_OF = (
794 1 => "%f:%l:%c:%m\n",
795 2 => "%f: (%l:%c) %m\n",
b57cebc1
JRT
796 3 => "%m at %f line %l\n",
797 4 => "%m at line %l, column %c. %e. (Severity: %s)\n",
798 5 => "%f: %m at line %l, column %c. %e. (Severity: %s)\n",
799 6 => "%m at line %l, near '%r'. (Severity: %s)\n",
800 7 => "%f: %m at line %l near '%r'. (Severity: %s)\n",
801 8 => "[%p] %m at line %l, column %c. (Severity: %s)\n",
802 9 => "[%p] %m at line %l, near '%r'. (Severity: %s)\n",
803 10 => "%m at line %l, column %c.\n %p (Severity: %s)\n%d\n",
804 11 => "%m at line %l, near '%r'.\n %p (Severity: %s)\n%d\n",
4268e673
JRT
805);
806
9f6df1c1
JRT
807my $DEFAULT_FORMAT = $FORMAT_OF{4};
808
4268e673 809sub verbosity_to_format {
9f6df1c1
JRT
810 my ($verbosity) = @_;
811 return $DEFAULT_FORMAT if not defined $verbosity;
812 return $FORMAT_OF{abs int $verbosity} || $DEFAULT_FORMAT if _is_integer($verbosity);
813 return interpolate( $verbosity ); #Otherwise, treat as a format spec
4268e673
JRT
814}
815
9f6df1c1
JRT
816sub _is_integer { return $_[0] =~ m{ \A [+-]? \d+ \z }mx }
817
4268e673
JRT
818#-----------------------------------------------------------------------------
819
0bcb38c0
JRT
820my %SEVERITY_NUMBER_OF = (
821 gentle => 5,
822 stern => 4,
823 harsh => 3,
824 cruel => 2,
825 brutal => 1,
826);
827
828our @SEVERITY_NAMES = sort { $SEVERITY_NUMBER_OF{$a} <=> $SEVERITY_NUMBER_OF{$b} }
829 keys %SEVERITY_NUMBER_OF; #This is exported!
830
831sub severity_to_number {
832 my ($severity) = @_;
833 return _normalize_severity( $severity ) if _is_integer( $severity );
834 my $severity_number = $SEVERITY_NUMBER_OF{lc $severity};
835 confess qq{Invalid severity: "$severity"} if not defined $severity_number;
836 return $severity_number;
837}
838
839sub _normalize_severity {
840 my $s = shift || return $SEVERITY_HIGHEST;
841 $s = $s > $SEVERITY_HIGHEST ? $SEVERITY_HIGHEST : $s;
842 $s = $s < $SEVERITY_LOWEST ? $SEVERITY_LOWEST : $s;
843 return $s;
844}
845
846#-----------------------------------------------------------------------------
847
a91b8a46
AL
848my @skip_dir = qw( CVS RCS .svn _darcs {arch} .bzr _build blib );
849my %skip_dir = hashify( @skip_dir );
850
8645eb2c
JRT
851sub all_perl_files {
852
853 # Recursively searches a list of directories and returns the paths
854 # to files that seem to be Perl source code. This subroutine was
855 # poached from Test::Perl::Critic.
856
8645eb2c
JRT
857 my @queue = @_;
858 my @code_files = ();
859
860 while (@queue) {
861 my $file = shift @queue;
862 if ( -d $file ) {
863 opendir my ($dh), $file or next;
864 my @newfiles = sort readdir $dh;
865 closedir $dh;
866
867 @newfiles = File::Spec->no_upwards(@newfiles);
868 @newfiles = grep { !$skip_dir{$_} } @newfiles;
869 push @queue, map { File::Spec->catfile($file, $_) } @newfiles;
870 }
871
872 if ( (-f $file) && ! _is_backup($file) && _is_perl($file) ) {
873 push @code_files, $file;
874 }
875 }
876 return @code_files;
877}
878
879
880#-----------------------------------------------------------------------------
881# Decide if it's some sort of backup file
882
883sub _is_backup {
884 my ($file) = @_;
885 return 1 if $file =~ m{ [.] swp \z}mx;
886 return 1 if $file =~ m{ [.] bak \z}mx;
887 return 1 if $file =~ m{ ~ \z}mx;
888 return 1 if $file =~ m{ \A [#] .+ [#] \z}mx;
889 return;
890}
891
892#-----------------------------------------------------------------------------
893# Returns true if the argument ends with a perl-ish file
894# extension, or if it has a shebang-line containing 'perl' This
895# subroutine was also poached from Test::Perl::Critic
896
897sub _is_perl {
898 my ($file) = @_;
899
900 #Check filename extensions
901 return 1 if $file =~ m{ [.] PL \z}mx;
902 return 1 if $file =~ m{ [.] p (?: l|m ) \z}mx;
903 return 1 if $file =~ m{ [.] t \z}mx;
904
905 #Check for shebang
906 open my ($fh), '<', $file or return;
907 my $first = <$fh>;
9fb2d1dc 908 close $fh or confess "unable to close $file: $!";
8645eb2c 909
e2e7b907 910 return 1 if defined $first && ( $first =~ m{ \A \#![ ]*\S*perl }mx );
8645eb2c
JRT
911 return;
912}
913
6036a254 914#-----------------------------------------------------------------------------
bf159007 915
e2e7b907
CD
916sub shebang_line {
917 my $doc = shift;
918 my $first_comment = $doc->find_first('PPI::Token::Comment');
919 return if !$first_comment;
920 my $location = $first_comment->location();
921 return if !$location;
922 # The shebang must be the first two characters in the file, according to
923 # http://en.wikipedia.org/wiki/Shebang_(Unix)
924 return if $location->[0] != 1; # line number
925 return if $location->[1] != 1; # column number
926 my $shebang = $first_comment->content;
927 return if $shebang !~ m{ \A \#\! }mx;
928 return $shebang;
929}
930
6036a254 931#-----------------------------------------------------------------------------
e2e7b907 932
4a7a7227
AL
933sub words_from_string {
934 my $str = shift;
935
38e3d924 936 return split q{ }, $str; # This must be a literal space, not $SPACE
4a7a7227
AL
937}
938
9fb2d1dc
AM
939#-----------------------------------------------------------------------------
940
941sub is_unchecked_call {
942 my $elem = shift;
943
944 return if not is_function_call( $elem );
945
946 # check to see if there's an '=' or 'unless' or something before this.
947 if( my $sib = $elem->sprevious_sibling() ){
948 return if $sib;
949 }
950
951
952 if( my $statement = $elem->statement() ){
953
954 # "open or die" is OK.
955 # We can't check snext_sibling for 'or' since the next siblings are an
956 # unknown number of arguments to the system call. Instead, check all of
40647aca
JRT
957 # the elements to this statement to see if we find 'or' or '||'.
958
959 my $or_operators = sub {
960 my (undef, $elem) = @_;
961 return if not $elem->isa('PPI::Token::Operator');
0f1f4df7 962 return if $elem ne q{or} && $elem ne q{||};
40647aca
JRT
963 return 1;
964 };
965
966 return if $statement->find( $or_operators );
967
9fb2d1dc
AM
968
969 if( my $parent = $elem->statement()->parent() ){
970
40647aca 971 # Check if we're in an if( open ) {good} else {bad} condition
9fb2d1dc
AM
972 return if $parent->isa('PPI::Structure::Condition');
973
40647aca 974 # Return val could be captured in data structure and checked later
9fb2d1dc
AM
975 return if $parent->isa('PPI::Structure::Constructor');
976
977 # "die if not ( open() )" - It's in list context.
978 if ( $parent->isa('PPI::Structure::List') ) {
979 if( my $uncle = $parent->sprevious_sibling() ){
980 return if $uncle;
981 }
982 }
983 }
984 }
985
986 # Otherwise, return. this system call is unchecked.
987 return 1;
988}
989
4a7a7227 990
59b05e08
JRT
9911;
992
993__END__
994
dff08b70
JRT
995=pod
996
59b05e08
JRT
997=head1 NAME
998
999Perl::Critic::Utils - Utility subs and vars for Perl::Critic
1000
1001=head1 DESCRIPTION
1002
bbf4108c
ES
1003This module provides several static subs and variables that are useful for
1004developing L<Perl::Critic::Policy> subclasses. Unless you are writing Policy
1005modules, you probably don't care about this package.
59b05e08 1006
bbf4108c 1007=head1 IMPORTABLE SUBS
59b05e08
JRT
1008
1009=over 8
1010
6d9feae6 1011=item C<find_keywords( $doc, $keyword )>
59b05e08 1012
bbf4108c
ES
1013B<DEPRECATED:> Since version 0.11, every Policy is evaluated at each element
1014of the document. So you shouldn't need to go looking for a particular
1015keyword. If you I<do> want to use this, please import it via the
1016C<:deprecated> tag, rather than directly, to mark the module as needing
1017updating.
59b05e08 1018
6d9feae6 1019Given a L<PPI::Document> as C<$doc>, returns a reference to an array
bbf4108c
ES
1020containing all the L<PPI::Token::Word> elements that match C<$keyword>. This
1021can be used to find any built-in function, method call, bareword, or reserved
1022keyword. It will not match variables, subroutine names, literal strings,
1023numbers, or symbols. If the document doesn't contain any matches, returns
1024undef.
59b05e08 1025
8d6b89b3
JRT
1026=item C<is_perl_global( $element )>
1027
3c71d40c 1028Given a L<PPI::Token::Symbol> or a string, returns true if that token
bbf4108c
ES
1029represents one of the global variables provided by the L<English> module, or
1030one of the builtin global variables like C<%SIG>, C<%ENV>, or C<@ARGV>. The
1031sigil on the symbol is ignored, so things like C<$ARGV> or C<$ENV> will still
1032return true.
8d6b89b3
JRT
1033
1034=item C<is_perl_builtin( $element )>
1035
c948abe5
ES
1036Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1037if that token represents a call to any of the builtin functions defined in
1038Perl 5.8.8.
1039
3ca95ec9
JRT
1040=item C<is_perl_bareword( $element )>
1041
1042Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1043if that token represents a bareword (e.g. "if", "else", "sub", "package")
1044defined in Perl 5.8.8.
1045
2c30044d
JRT
1046=item C<is_perl_filehandle( $element )>
1047
1048Given a L<PPI::Token::Word>, or string, returns true if that token represents
1049one of the global filehandles (e.g. C<STDIN>, C<STDERR>, C<STDOUT>, C<ARGV>)
1050that are defined in Perl 5.8.8. Note that this function will return false if
1051given a filehandle that is represented as a typeglob (e.g. C<*STDIN>)
1052
c948abe5
ES
1053=item C<is_perl_builtin_with_list_context( $element )>
1054
1055Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1056if that token represents a call to any of the builtin functions defined in
27ac78c7 1057Perl 5.8.8 that provide a list context to the following tokens.
c948abe5
ES
1058
1059=item C<is_perl_builtin_with_multiple_arguments( $element )>
1060
1061Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1062if that token represents a call to any of the builtin functions defined in
27ac78c7
ES
1063Perl 5.8.8 that B<can> take multiple arguments.
1064
1065=item C<is_perl_builtin_with_no_arguments( $element )>
1066
1067Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1068if that token represents a call to any of the builtin functions defined in
1069Perl 5.8.8 that B<cannot> take any arguments.
1070
1071=item C<is_perl_builtin_with_one_argument( $element )>
1072
1073Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1074if that token represents a call to any of the builtin functions defined in
1075Perl 5.8.8 that takes B<one and only one> argument.
1076
1077=item C<is_perl_builtin_with_optional_argument( $element )>
1078
1079Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1080if that token represents a call to any of the builtin functions defined in
1081Perl 5.8.8 that takes B<no more than one> argument.
1082
1083The sets of values for which C<is_perl_builtin_with_multiple_arguments()>,
1084C<is_perl_builtin_with_no_arguments()>,
1085C<is_perl_builtin_with_one_argument()>, and
1086C<is_perl_builtin_with_optional_argument()> return true are disjoint and
1087their union is precisely the set of values that C<is_perl_builtin()> will
1088return true for.
1089
1090=item C<is_perl_builtin_with_zero_and_or_one_arguments( $element )>
1091
1092Given a L<PPI::Token::Word>, L<PPI::Statement::Sub>, or string, returns true
1093if that token represents a call to any of the builtin functions defined in
1094Perl 5.8.8 that takes no and/or one argument.
1095
1096Returns true if any of C<is_perl_builtin_with_no_arguments()>,
1097C<is_perl_builtin_with_one_argument()>, and
1098C<is_perl_builtin_with_optional_argument()> returns true.
8d6b89b3 1099
ee3a2f51
ES
1100=item C<is_qualified_name( $name )>
1101
1102Given a string, L<PPI::Token::Word>, or L<PPI::Token::Symbol>, answers
1103whether it has a module component, i.e. contains "::".
1104
8d6b89b3
JRT
1105=item C<precedence_of( $element )>
1106
bbf4108c
ES
1107Given a L<PPI::Token::Operator> or a string, returns the precedence of the
1108operator, where 1 is the highest precedence. Returns undef if the precedence
1109can't be determined (which is usually because it is not an operator).
8d6b89b3 1110
6d9feae6 1111=item C<is_hash_key( $element )>
59b05e08 1112
bbf4108c
ES
1113Given a L<PPI::Element>, returns true if the element is a hash key. PPI
1114doesn't distinguish between regular barewords (like keywords or subroutine
1115calls) and barewords in hash subscripts (which are considered literal). So
1116this subroutine is useful if your Policy is searching for L<PPI::Token::Word>
1117elements and you want to filter out the hash subscript variety. In both of
f7a00b57 1118the following examples, "foo" is considered a hash key:
59b05e08
JRT
1119
1120 $hash1{foo} = 1;
1121 %hash2 = (foo => 1);
1122
bdaf4dac
ES
1123=item C<is_included_module_name( $element )>
1124
1125Given a L<PPI::Token::Word>, returns true if the element is the name of a
1126module that is being included via C<use>, C<require>, or C<no>.
1127
f7a00b57
JRT
1128=item C<is_class_name( $element )>
1129
1130Given a L<PPI::Token::Word>, returns true if the element that immediately
1131follows this element is the dereference operator "->". When a bareword has a
1132"->" on the B<right> side, it usually means that it is the name of the class
1133(from which a method is being called).
1134
aa0d7c6e
JRT
1135=item C<is_label_pointer( $element )>
1136
1137Given a L<PPI::Token::Word>, returns true if the element is the label
1138in a C<next>, C<last>, C<redo>, or C<goto> statement. Note this is not the
1139same thing as the label declaration.
1140
6d9feae6 1141=item C<is_method_call( $element )>
59b05e08 1142
f7a00b57
JRT
1143Given a L<PPI::Token::Word>, returns true if the element that immediately
1144precedes this element is the dereference operator "->". When a bareword has a
1145"->" on the B<left> side, it usually means that it is the name of a method
1146(that is being called from a class).
59b05e08 1147
bdaf4dac 1148=item C<is_package_declaration( $element )>
0c377685 1149
bbf4108c 1150Given a L<PPI::Token::Word>, returns true if the element is the name of a
bdaf4dac 1151package that is being declared.
0c377685 1152
bdaf4dac 1153=item C<is_subroutine_name( $element )>
0893757b
ES
1154
1155Given a L<PPI::Token::Word>, returns true if the element is the name of a
bdaf4dac
ES
1156subroutine declaration. This is useful for distinguishing barewords and from
1157function calls from subroutine declarations.
0893757b 1158
dc118d1b
JRT
1159=item C<is_function_call( $element )>
1160
bbf4108c
ES
1161Given a L<PPI::Token::Word> returns true if the element appears to be call to
1162a static function. Specifically, this function returns true if
3ca95ec9
JRT
1163C<is_hash_key>, C<is_method_call>, C<is_subroutine_name>,
1164C<is_included_module_anme>, C<is_package_declaration>, C<is_perl_bareword>,
aa0d7c6e
JRT
1165C<is_perl_filehandle>, C<is_label_pointer> and C<is_subroutine_name> all
1166return false for the given element.
dc118d1b 1167
14a6a3ef
CD
1168=item C<first_arg( $element )>
1169
1170Given a L<PPI::Element> that is presumed to be a function call (which is
bbf4108c
ES
1171usually a L<PPI::Token::Word>), return the first argument. This is similar of
1172C<parse_arg_list()> and follows the same logic. Note that for the code:
14a6a3ef
CD
1173
1174 int($x + 0.5)
1175
1176this function will return just the C<$x>, not the whole expression. This is
1177different from the behavior of C<parse_arg_list()>. Another caveat is:
1178
1179 int(($x + $y) + 0.5)
1180
1181which returns C<($x + $y)> as a L<PPI::Structure::List> instance.
1182
6d9feae6 1183=item C<parse_arg_list( $element )>
59b05e08 1184
bbf4108c
ES
1185Given a L<PPI::Element> that is presumed to be a function call (which is
1186usually a L<PPI::Token::Word>), splits the argument expressions into arrays of
1187tokens. Returns a list containing references to each of those arrays. This
1188is useful because parens are optional when calling a function, and PPI parses
1189them very differently. So this method is a poor-man's parse tree of PPI
1190nodes. It's not bullet-proof because it doesn't respect precedence. In
1191general, I don't like the way this function works, so don't count on it to be
1192stable (or even present).
59b05e08 1193
6d9feae6 1194=item C<is_script( $document )>
bf159007 1195
bbf4108c
ES
1196Given a L<PPI::Document>, test if it starts with C</#!.*/>. If so, it is
1197judged to be a script instead of a module. See C<shebang_line()>.
bf159007 1198
bbf4108c 1199=item C< policy_long_name( $policy_name ) >
dc93df4f 1200
bbf4108c
ES
1201Given a policy class name in long or short form, return the long form.
1202
1203=item C< policy_short_name( $policy_name ) >
1204
1205Given a policy class name in long or short form, return the short form.
dc93df4f 1206
8645eb2c
JRT
1207=item C<all_perl_files( @directories )>
1208
bbf4108c
ES
1209Given a list of directories, recursively searches through all the directories
1210(depth first) and returns a list of paths for all the files that are Perl code
1211files. Any administrative files for CVS or Subversion are skipped, as are
1212things that look like temporary or backup files.
8645eb2c
JRT
1213
1214A Perl code file is:
1215
1216=over 4
1217
1218=item * Any file that ends in F<.PL>, F<.pl>, F<.pm>, or F<.t>
1219
1220=item * Any file that has a first line with a shebang containing 'perl'
1221
1222=back
1223
0bcb38c0
JRT
1224=item C<severity_to_number( $severity )>
1225
1226If C<$severity> is given as an integer, this function returns C<$severity> but
1227normalized to lie between C<$SEVERITY_LOWEST> and C<$SEVERITY_HIGHEST>. If
1228C<$severity> is given as a string, this function returns the corresponding
1229severity number. If the string doesn't have a corresponding number, this
1230function will throw an exception.
1231
4268e673
JRT
1232=item C<verbosity_to_format( $verbosity_level )>
1233
bbf4108c
ES
1234Given a verbosity level between 1 and 10, returns the corresponding predefined
1235format string. These formats are suitable for passing to the C<set_format>
1236method in L<Perl::Critic::Violation>. See the L<perlcritic> documentation for
1237a listing of the predefined formats.
4268e673 1238
3ffdaa3b
AL
1239=item C<hashify( @list )>
1240
bbf4108c
ES
1241Given C<@list>, return a hash where C<@list> is in the keys and each value is
12421. Duplicate values in C<@list> are silently squished.
7b84ff16
JRT
1243
1244=item C<interpolate( $literal )>
1245
bbf4108c
ES
1246Given a C<$literal> string that may contain control characters (e.g.. '\t'
1247'\n'), this function does a double interpolation on the string and returns it
1248as if it had been declared in double quotes. For example:
7b84ff16
JRT
1249
1250 'foo \t bar \n' ...becomes... "foo \t bar \n"
3ffdaa3b 1251
e2e7b907
CD
1252=item C<shebang_line( $document )>
1253
bbf4108c
ES
1254Given a L<PPI::Document>, test if it starts with C<#!>. If so, return that
1255line. Otherwise return undef.
e2e7b907 1256
4a7a7227
AL
1257=item C<words_from_string( $str )>
1258
bbf4108c
ES
1259Given config string I<$str>, return all the words from the string. This is
1260safer than splitting on whitespace.
4a7a7227 1261
9fb2d1dc
AM
1262=item C<is_unchecked_call( $element )>
1263
1264Given a L<PPI::Element>, test to see if it contains a function call whose
1265return value is not checked.
1266
59b05e08
JRT
1267=back
1268
bbf4108c 1269=head1 IMPORTABLE VARIABLES
59b05e08
JRT
1270
1271=over 8
1272
6d9feae6 1273=item C<$COMMA>
59b05e08 1274
a3adb7a9
AL
1275=item C<$FATCOMMA>
1276
6d9feae6 1277=item C<$COLON>
59b05e08 1278
6d9feae6 1279=item C<$SCOLON>
59b05e08 1280
6d9feae6 1281=item C<$QUOTE>
59b05e08 1282
6d9feae6 1283=item C<$DQUOTE>
59b05e08 1284
6d9feae6 1285=item C<$PERIOD>
59b05e08 1286
6d9feae6 1287=item C<$PIPE>
59b05e08 1288
6d9feae6 1289=item C<$EMPTY>
59b05e08 1290
6d9feae6 1291=item C<$SPACE>
59b05e08 1292
a609ec83
ES
1293=item C<$SLASH>
1294
1295=item C<$BSLASH>
1296
310e7cf9
ES
1297=item C<$LEFT_PAREN>
1298
1299=item C<$RIGHT_PAREN>
1300
bbf4108c
ES
1301These character constants give clear names to commonly-used strings that can
1302be hard to read when surrounded by quotes and other punctuation. Can be
1303imported in one go via the C<:characters> tag.
dff08b70 1304
6d9feae6 1305=item C<$SEVERITY_HIGHEST>
dff08b70 1306
6d9feae6 1307=item C<$SEVERITY_HIGH>
dff08b70 1308
6d9feae6 1309=item C<$SEVERITY_MEDIUM>
dff08b70 1310
6d9feae6 1311=item C<$SEVERITY_LOW>
dff08b70 1312
6d9feae6 1313=item C<$SEVERITY_LOWEST>
dff08b70 1314
7e86d49a 1315These numeric constants define the relative severity of violating each
bbf4108c
ES
1316L<Perl::Critic::Policy>. The C<get_severity> and C<default_severity> methods
1317of every Policy subclass must return one of these values. Can be imported via
1318the C<:severities> tag.
dff08b70 1319
6d9feae6 1320=item C<$TRUE>
59b05e08 1321
6d9feae6 1322=item C<$FALSE>
59b05e08
JRT
1323
1324These are simple booleans. 1 and 0 respectively. Be mindful of using these
bbf4108c
ES
1325with string equality. C<$FALSE ne $EMPTY>. Can be imported via the
1326C<:booleans> tag.
1327
1328=back
1329
1330=head1 IMPORT TAGS
1331
1332The following groups of functions and constants are available as parameters to
1333a C<use Perl::Critic::Util> statement.
1334
1335=over
1336
1337=item C<:all>
1338
1339The lot.
1340
1341=item C<:booleans>
1342
1343Includes:
1344C<$TRUE>, C<$FALSE>
1345
1346=item C<:severities>
1347
1348Includes:
1349C<$SEVERITY_HIGHEST>,
1350C<$SEVERITY_HIGH>,
1351C<$SEVERITY_MEDIUM>,
1352C<$SEVERITY_LOW>,
1353C<$SEVERITY_LOWEST>,
1354C<@SEVERITY_NAMES>
1355
1356=item C<:characters>
1357
1358Includes:
1359C<$COLON>,
1360C<$COMMA>,
1361C<$DQUOTE>,
1362C<$EMPTY>,
1363C<$FATCOMMA>,
1364C<$PERIOD>,
1365C<$PIPE>,
1366C<$QUOTE>,
1367C<$SCOLON>,
1368C<$SPACE>,
1369C<$SLASH>,
1370C<$BSLASH>
310e7cf9
ES
1371C<$LEFT_PAREN>
1372C<$RIGHT_PAREN>
bbf4108c
ES
1373
1374=item C<:classification>
1375
1376Includes:
1377C<&is_function_call>,
1378C<&is_hash_key>,
0893757b 1379C<&is_included_module_name>,
bbf4108c 1380C<&is_method_call>,
bdaf4dac 1381C<&is_package_declaration>,
bbf4108c
ES
1382C<&is_perl_builtin>,
1383C<&is_perl_global>,
1384C<&is_script>,
1385C<&is_subroutine_name>,
1386C<&is_unchecked_call>
1387
1388=item C<:data_conversion>
1389
1390Generic manipulation, not having anything specific to do with Perl::Critic.
1391
1392Includes:
1393C<&hashify>,
1394C<&words_from_string>,
1395C<&interpolate>
1396
1397=item C<:ppi>
1398
1399Things for dealing with L<PPI>, other than classification.
1400
1401Includes:
1402C<&first_arg>,
1403C<&parse_arg_list>
1404
1405=item C<:internal_lookup>
1406
1407Translations between internal representations.
1408
1409Includes:
1410C<&severity_to_number>,
1411C<&verbosity_to_format>
1412
1413=item C<:language>
1414
1415Information about Perl not programmatically available elsewhere.
1416
1417Includes:
1418C<&precedence_of>
1419
1420=item C<:deprecated>
1421
1422Not surprisingly, things that are deprecated. It is preferred to use this tag
1423to get to these functions, rather than the function names themselves, so as to
1424mark any module using them as needing cleanup.
1425
1426Includes:
1427C<&find_keywords>
59b05e08
JRT
1428
1429=back
1430
1431=head1 AUTHOR
1432
1433Jeffrey Ryan Thalhammer <thaljef@cpan.org>
1434
1435=head1 COPYRIGHT
1436
0d5b2dca 1437Copyright (c) 2005-2007 Jeffrey Ryan Thalhammer. All rights reserved.
59b05e08
JRT
1438
1439This program is free software; you can redistribute it and/or modify
1440it under the same terms as Perl itself. The full text of this license
1441can be found in the LICENSE file included with this module.
dff08b70
JRT
1442
1443=cut
737d3b65
CD
1444
1445# Local Variables:
1446# mode: cperl
1447# cperl-indent-level: 4
1448# fill-column: 78
1449# indent-tabs-mode: nil
1450# c-indentation-style: bsd
1451# End:
345c7562 1452# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab :