PPIx::U...fication(3)

πŸ’– PPIx::Utils::Classification πŸ’–

okay so bestie, gather round, because this is PPIx::Utils::Classification, straight outta the User Contributed Perl Documentation collection, and it is exactly what it says on the tin: utility functions for classification of PPI elements. she's a whole vibe. let's get into it. πŸŽ€


✨ NAME ✨

PPIx::Utils::Classification β€” Utility functions for classification of PPI elements


🌸 SYNOPSIS 🌸

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

like, that's it. that's the whole entrance. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

This package is a component of PPIx::Utils that contains functions for classification of PPI elements. she's part of a bigger friend group, but she's got her own thing going on. ✨


πŸ’œ FUNCTIONS πŸ’œ

All functions can be imported by name, or with the tag :all. pick your fighter β€” named imports or the whole squad, no cap.

🌈 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.). bestie is checking if something's assigning, periodt.

🌈 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. iconic behavior honestly.

🌈 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.

⚠️ heads up bestie: this function will return false if given a filehandle that is represented as a typeglob (e.g. *STDIN). she said no typeglobs today. πŸ™ˆ

🌈 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. she's not like other girls, she takes many args. πŸ’…

🌈 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. zero. none. no args allowed. boundaries, bestie. 🚫

🌈 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. not two. not zero. exactly one. she's monogamous.

🌈 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. no overlap, no leftovers β€” a perfect little partition, honestly iconic. 🌈

🌈 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. so like, it's the group chat of those three. 🫢

🌈 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 "::". the double colon is the giveaway, iykyk.

🌈 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);

see how the parentheses change everything?? it's giving plot twist. 😭

🌈 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). right side = class. noted. πŸ‘‘

🌈 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 bestie: this is not the same thing as the label declaration. different thing entirely, don't mix them up. πŸ™ˆ

🌈 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). left side = method. the mirror image of is_class_name, cute. πŸͺž

🌈 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. (yes, that sentence is shaped like that in the original β€” we don't gatekeep, we preserve. πŸ’…)

🌈 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.

(yes, is_subroutine_name is in that list twice. we said what we said. it's in the original, it's in here, character for character. no cap.)

🌈 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. the void, bestie. the nothingness. πŸ•³οΈ

🌈 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. bold move honestly. 😬

🌈 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. the whole squad, listed out. 🫢

🌈 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.

⚠️ bestie listen: 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.
⚠️ also: this subroutine also does not interpret entities created by the ReadonlyX module (or similar) or the constant pragma as constants. so like, don't @ her about those. πŸ™…

🌈 is_subroutine_declaration

my $bool = is_subroutine_declaration($element);

Is the parameter a subroutine declaration, named or not? short and sweet, she's efficient. ⭐

🌈 is_in_subroutine

my $bool = is_in_subroutine($element);

Is the parameter a subroutine or inside one? are you in the sub, or are you the sub? philosophical, honestly. πŸ¦‹


πŸ’€ BUGS πŸ’€

Report any issues on the public bugtracker. don't suffer in silence, bestie, tell the maintainers. πŸ™


πŸ‘‘ 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>

the lore is real, the lineage is real. respect the ancestors. 🫢


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. free as in, go wild, but keep the license terms, periodt. πŸ’…


🌈 SEE ALSO 🌈

  • Perl::Critic::Utils
  • Perl::Critic::Utils::PPI

and that's the whole page, bestie!! πŸŽ€βœ¨ she ships as part of perl v5.42.0 and this version is dated 2025-08-05 β€” so like, go forth and classify your PPI elements with main character energy. ate. no crumbs. πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from