| Perl::Critic::Utils - Utility subs and vars for Perl::Critic |
Perl::Critic::Utils - Utility subs and vars for Perl::Critic
This module provides several static subs and variables that are useful for developing the Perl::Critic::Policy manpage subclasses. Unless you are writing Policy modules, you probably don't care about this package.
find_keywords( $doc, $keyword ):deprecated tag, rather than directly, to mark the module as needing
updating.
Given a the PPI::Document manpage as $doc, returns a reference to an array
containing all the the PPI::Token::Word manpage elements that match $keyword. This
can be used to find any built-in function, method call, bareword, or reserved
keyword. It will not match variables, subroutine names, literal strings,
numbers, or symbols. If the document doesn't contain any matches, returns
undef.
is_perl_global( $element )%SIG, %ENV, or @ARGV. The
sigil on the symbol is ignored, so things like $ARGV or $ENV will still
return true.
is_perl_builtin( $element )is_perl_bareword( $element )is_perl_filehandle( $element )STDIN, STDERR, STDOUT, ARGV)
that are defined in Perl 5.8.8. Note that this function will return false if
given a filehandle that is represented as a typeglob (e.g. *STDIN)
is_perl_builtin_with_list_context( $element )is_perl_builtin_with_multiple_arguments( $element )is_perl_builtin_with_no_arguments( $element )is_perl_builtin_with_one_argument( $element )is_perl_builtin_with_optional_argument( $element )The sets of values for which is_perl_builtin_with_multiple_arguments(),
is_perl_builtin_with_no_arguments(),
is_perl_builtin_with_one_argument(), and
is_perl_builtin_with_optional_argument() return true are disjoint and
their union is precisely the set of values that is_perl_builtin() will
return true for.
is_perl_builtin_with_zero_and_or_one_arguments( $element )Returns true if any of is_perl_builtin_with_no_arguments(),
is_perl_builtin_with_one_argument(), and
is_perl_builtin_with_optional_argument() returns true.
is_qualified_name( $name )precedence_of( $element )is_hash_key( $element )
$hash1{foo} = 1;
%hash2 = (foo => 1);
But if the bareword is followed by an argument list, then perl treats it as a function call. So in these examples, ``foo'' is not considered a hash key:
$hash1{ foo() } = 1;
&hash2 = (foo() => 1);
is_included_module_name( $element )use, require, or no.
is_integer( $value )is_class_name( $element )is_label_pointer( $element )next, last, redo, or goto statement. Note this is not the
same thing as the label declaration.
is_method_call( $element )is_package_declaration( $element )is_subroutine_name( $element )is_function_call( $element )is_hash_key, is_method_call, is_subroutine_name,
is_included_module_anme, is_package_declaration, is_perl_bareword,
is_perl_filehandle, is_label_pointer and is_subroutine_name all
return false for the given element.
first_arg( $element )parse_arg_list() and follows the same logic. Note that for the code:
int($x + 0.5)
this function will return just the $x, not the whole expression. This is
different from the behavior of parse_arg_list(). Another caveat is:
int(($x + $y) + 0.5)
which returns ($x + $y) as a the PPI::Structure::List manpage instance.
parse_arg_list( $element )split_nodes_on_comma( @nodes )parse_arg_list() but expects to be passed
the nodes that represent the interior of a list, like:
'foo', 1, 2, 'bar'
is_script( $document )/#!.*/. If so, it is
judged to be a script instead of a module. See shebang_line().
is_in_void_context( $token )policy_long_name( $policy_name )policy_short_name( $policy_name )all_perl_files( @directories )A Perl code file is:
severity_to_number( $severity )$severity is given as an integer, this function returns $severity but
normalized to lie between $SEVERITY_LOWEST and $SEVERITY_HIGHEST. If
$severity is given as a string, this function returns the corresponding
severity number. If the string doesn't have a corresponding number, this
function will throw an exception.
is_valid_numeric_verbosity( $severity )verbosity_to_format( $verbosity_level )set_format
method in the Perl::Critic::Violation manpage. See the perlcritic documentation for
a listing of the predefined formats.
hashify( @list )@list, return a hash where @list is in the keys and each value is
1. Duplicate values in @list are silently squished.
interpolate( $literal )$literal string that may contain control characters (e.g.. '\t'
'\n'), this function does a double interpolation on the string and returns it
as if it had been declared in double quotes. For example:
'foo \t bar \n' ...becomes... "foo \t bar \n"
shebang_line( $document )#!. If so, return that
line. Otherwise return undef.
words_from_string( $str )is_unchecked_call( $element )
$COMMA$FATCOMMA$COLON$SCOLON$QUOTE$DQUOTE$BACKTICK$PERIOD$PIPE$EMPTY$SPACE$SLASH$BSLASH$LEFT_PAREN$RIGHT_PAREN:characters tag.
$SEVERITY_HIGHEST$SEVERITY_HIGH$SEVERITY_MEDIUM$SEVERITY_LOW$SEVERITY_LOWESTget_severity and default_severity methods
of every Policy subclass must return one of these values. Can be imported via
the :severities tag.
$DEFAULT_VERBOSITY$DEFAULT_VERBOSITY_WITH_FILE_NAME$DEFAULT_VERBOSITY, but with the file name prefixed to it.
$TRUE$FALSE$FALSE ne $EMPTY. Can be imported via the
:booleans tag.
The following groups of functions and constants are available as parameters to
a use Perl::Critic::Util statement.
:all:booleans$TRUE, $FALSE
:severities$SEVERITY_HIGHEST,
$SEVERITY_HIGH,
$SEVERITY_MEDIUM,
$SEVERITY_LOW,
$SEVERITY_LOWEST,
@SEVERITY_NAMES
:characters$COLON,
$COMMA,
$DQUOTE,
$EMPTY,
$FATCOMMA,
$PERIOD,
$PIPE,
$QUOTE,
$BACKTICK,
$SCOLON,
$SPACE,
$SLASH,
$BSLASH
$LEFT_PAREN
$RIGHT_PAREN
:classificationis_function_call,
is_hash_key,
is_included_module_name,
is_integer,
is_method_call,
is_package_declaration,
is_perl_builtin,
is_perl_global,
is_perl_builtin_with_list_context
is_perl_builtin_with_multiple_arguments
is_perl_builtin_with_no_arguments
is_perl_builtin_with_one_argument
is_perl_builtin_with_optional_argument
is_perl_builtin_with_zero_and_or_one_arguments
is_script,
is_subroutine_name,
is_unchecked_call
is_valid_numeric_verbosity
See also the Perl::Critic::Utils::PPI manpage.
:data_conversionIncludes:
hashify,
words_from_string,
interpolate
:ppiIncludes:
first_arg,
parse_arg_list
See also the Perl::Critic::Utils::PPI manpage.
:internal_lookupIncludes:
severity_to_number,
verbosity_to_format
:languageIncludes:
precedence_of
:deprecatedIncludes:
find_keywords
the Perl::Critic::Utils::Constants manpage, the Perl::Critic::Utils::McCabe manpage, the Perl::Critic::Utils::PPI manpage,
Jeffrey Ryan Thalhammer <thaljef@cpan.org>
Copyright (c) 2005-2007 Jeffrey Ryan Thalhammer. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.
| Perl::Critic::Utils - Utility subs and vars for Perl::Critic |