NAME

PPIx::Utils::Classification - Utility functions for classification of PPI elements

SYNOPSIS

use PPIx::Utils::Classification ':all';

DESCRIPTION

This package is a component of PPIx::Utils that contains functions for classification of PPI elements.

FUNCTIONS

All functions can be imported by name, or with the tag :all.

is_assignment_operator

my $bool = is_assignment_operator($element);

Given a PPI::Token::Operator or a string, returns true if that token represents one of the assignment operators (e.g. = &&= ||= //= += -= etc.).

is_perl_global

my $bool = is_perl_global($element);

Given a PPI::Token::Symbol or a string, returns true if that token represents one of the global variables provided by the English module, or one of the builtin global variables like %SIG, %ENV, or @ARGV. The sigil on the symbol is ignored, so things like $ARGV or $ENV will still return true.

is_perl_builtin

my $bool = is_perl_builtin($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8.

is_perl_bareword

my $bool = is_perl_bareword($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a bareword (e.g. "if", "else", "sub", "package") defined in Perl 5.8.8.

is_perl_filehandle

my $bool = is_perl_filehandle($element);

Given a PPI::Token::Word, or string, returns true if that token represents one of the global filehandles (e.g. 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

my $bool = is_perl_builtin_with_list_context($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that provide a list context to the following tokens.

is_perl_builtin_with_multiple_arguments

my $bool = is_perl_builtin_with_multiple_arguments($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that can take multiple arguments.

is_perl_builtin_with_no_arguments

my $bool = is_perl_builtin_with_no_arguments($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that cannot take any arguments.

is_perl_builtin_with_one_argument

my $bool = is_perl_builtin_with_one_argument($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes one and only one argument.

is_perl_builtin_with_optional_argument

my $bool = is_perl_builtin_with_optional_argument($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes no more than one argument.

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

my $bool = is_perl_builtin_with_zero_and_or_one_arguments($element);

Given a PPI::Token::Word, PPI::Statement::Sub, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes no and/or one argument.

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

my $bool = is_qualified_name($name);

Given a string, PPI::Token::Word, or PPI::Token::Symbol, answers whether it has a module component, i.e. contains "::".

is_hash_key

my $bool = is_hash_key($element);

Given a PPI::Element, returns true if the element is a literal hash key. PPI doesn't distinguish between regular barewords (like keywords or subroutine calls) and barewords in hash subscripts (which are considered literal). So this subroutine is useful if your Policy is searching for PPI::Token::Word elements and you want to filter out the hash subscript variety. In both of the following examples, "foo" is considered a hash key:

$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

my $bool = is_included_module_name($element);

Given a PPI::Token::Word, returns true if the element is the name of a module that is being included via use, require, or no.

is_integer

my $bool = is_integer($value);

Answers whether the parameter, as a string, looks like an integral value.

is_class_name

my $bool = is_class_name($element);

Given a PPI::Token::Word, returns true if the element that immediately follows this element is the dereference operator "->". When a bareword has a "->" on the right side, it usually means that it is the name of the class (from which a method is being called).

is_label_pointer

my $bool = is_label_pointer($element);

Given a PPI::Token::Word, returns true if the element is the label in a next, last, redo, or goto statement. Note this is not the same thing as the label declaration.

is_method_call

my $bool = is_method_call($element);

Given a PPI::Token::Word, returns true if the element that immediately precedes this element is the dereference operator "->". When a bareword has a "->" on the left side, it usually means that it is the name of a method (that is being called from a class).

is_package_declaration

my $bool = is_package_declaration($element);

Given a PPI::Token::Word, returns true if the element is the name of a package that is being declared.

is_subroutine_name

my $bool = is_subroutine_name($element);

Given a PPI::Token::Word, returns true if the element is the name of a subroutine declaration. This is useful for distinguishing barewords and from function calls from subroutine declarations.

is_function_call

my $bool = is_function_call($element);

Given a PPI::Token::Word returns true if the element appears to be call to a static function. Specifically, this function returns true if "is_hash_key", "is_method_call", "is_subroutine_name", "is_included_module_name", "is_package_declaration", "is_perl_bareword", "is_perl_filehandle", "is_label_pointer" and "is_subroutine_name" all return false for the given element.

is_in_void_context

my $bool = is_in_void_context($token);

Given a PPI::Token, answer whether it appears to be in a void context.

is_unchecked_call

my $bool = is_unchecked_call($element);

Given a PPI::Element, test to see if it contains a function call whose return value is not checked.

is_ppi_expression_or_generic_statement

my $bool = is_ppi_expression_or_generic_statement($element);

Answers whether the parameter is an expression or an undifferentiated statement. I.e. the parameter either is a PPI::Statement::Expression or the class of the parameter is PPI::Statement and not one of its subclasses other than Expression.

is_ppi_generic_statement

my $bool = is_ppi_generic_statement($element);

Answers whether the parameter is an undifferentiated statement, i.e. the parameter is a PPI::Statement but not one of its subclasses.

is_ppi_statement_subclass

my $bool = is_ppi_statement_subclass($element);

Answers whether the parameter is a specialized statement, i.e. the parameter is a PPI::Statement but the class of the parameter is not PPI::Statement.

is_ppi_simple_statement

my $bool = is_ppi_simple_statement($element);

Answers whether the parameter represents a simple statement, i.e. whether the parameter is a PPI::Statement, PPI::Statement::Break, PPI::Statement::Include, PPI::Statement::Null, PPI::Statement::Package, or PPI::Statement::Variable.

is_ppi_constant_element

my $bool = is_ppi_constant_element($element);

Answers whether the parameter represents a constant value, i.e. whether the parameter is a PPI::Token::Number, PPI::Token::Quote::Literal, PPI::Token::Quote::Single, or PPI::Token::QuoteLike::Words, or is a PPI::Token::Quote::Double or PPI::Token::Quote::Interpolate which does not in fact contain any interpolated variables.

This subroutine does not interpret any form of here document as a constant value, and may not until PPI::Token::HereDoc acquires the relevant portions of the PPI::Token::Quote interface.

This subroutine also does not interpret entities created by the ReadonlyX module (or similar) or the constant pragma as constants.

is_subroutine_declaration

my $bool = is_subroutine_declaration($element);

Is the parameter a subroutine declaration, named or not?

is_in_subroutine

my $bool = is_in_subroutine($element);

Is the parameter a subroutine or inside one?

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <dbook@cpan.org>

Code originally from Perl::Critic::Utils by Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> and Perl::Critic::Utils::PPI by Elliot Shank <perl@galumph.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2017 Dan Book.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

SEE ALSO

Perl::Critic::Utils, Perl::Critic::Utils::PPI