NAME

App::perl::distrolint::CheckRole::TreeSitterPerl - role for checks that parse Perl source code

DESCRIPTION

This role provides a number of helper methods for implementing check classes that parse Perl source code, by using tree-sitter-perl.

METHODS

tree_sitter_perl

$ts = $check->tree_sitter_perl;

Returns a singleton Text::Treesitter instance configured for parsing the Perl language, using tree-sitter-perl.

parse_perl_string

$tree = $check->parse_perl_string( $str );

Returns a cached Text::Treesitter::Tree instance obtained by parsing the given source string. As multiple checks may wish to inspect the same file, and hence build the same tree, this will be cached and re-returned as necessary.

parse_perl_file

$tree = $check->parse_perl_file( $path );

A convenient shortcut for reading the text of the given path, then parsing it using "parse_perl_string".

walk_each_statement

$ok = $check->walk_each_statement( $node, $method, @args );

   $ok = $self->$method( $child_node, @args );

A trampoline method that invokes the method on the given arguments on every statement node found as a descendent of the node passed in.

Stops and returns false the first time the invoked method returns false, or returns true if the invoked method returns true for every call.

walk_each_query_match

$ok = $check->walk_each_query_match( $src, $node, $method, @args );

   $ok = $self->$method( \%captures, @args );

A trampoline method that invokes the method on the given arguments on every match of the given query source against the node passed in.

Stops and returns false the first time the invoked method returns false, or returns true if the invoked method returns true for every call.

The invoked method is passed a reference to a hash, containing mappings from capture names to the nodes of the tree that were captured by them.

extract_use_module_imports

@imports = $check->extract_use_module_imports( $node );

Given a (use_statement) node, analyse it to determine a list of statically-known import strings and return it. Simple string literals in 'single quotes', "double quotes" or qw( quoted word lists ) are parsed fairly simply. Other kinds of expressions are ignored.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>