Perl::Tags::Naive(3)
π NAME
Perl::Tags::Naive β bestie, the name literally tells you the whole story. It's a naive implementation. That's not a read, it's a flex. π«Ά
β¨ DESCRIPTION
Okay so, "naive" here means it's built on the classic pltags.pl script that ships with Perl, and honestly? By and large that's a better bet than the results produced by ctags. No cap. π₯
But β and I need you to hear me on this β a "better" approach may be to integrate this with PPI. So it's giving iconic, but with room to grow. π±
π Subclassing
Want a fully working example? Go look at TodoTagger in the t/ directory of the distribution (it's tested in <t/02_subclass.t>, so you know it actually works π
). You can reuse the parsers in the ::Naive package, or you can take all of the existing parsers and add your own on top. Mix and match, it's your world.
package My::Tagger;
use Perl::Tags;
use parent 'Perl::Tags::Naive';
sub get_parsers {
my $self = shift;
return (
$self->can('todo_line'), # a new parser
$self->SUPER::get_parsers(), # all ::Naive's parsers
# or maybe...
$self->can('variable'), # one of ::Naive's parsers
);
}
sub todo_line {
# your new parser code here!
}
sub package_line {
# override one of ::Naive's parsers
}
Here's the little secret that makes all this so cute: because ::Naive uses can('parser') instead of "\&parser", you can just override a particular parser by redefining it in the subclass. That's it. That's the whole trick. π§β¨
π¦ get_tags_for_file
::Naive does a simple line-by-line analysis of Perl code, comparing each line against an array of parsers returned by the get_parsers method.
The first of these parsers that matches (if any) will return the tag/control to be registered by the tagger. First match wins, periodt. π
π get_parsers
These are the parsers this module defines. Say hi π
πΈ trim
A filter rather than a parser β it removes whitespace and comments. Not a parser, just a little cleanup crew. π§Ή
π variable
Tags definitions of my, our, and local variables.
Returns a Perl::Tags::Tag::Var if found. π
π package_line
Parse a package declaration, returning a Perl::Tags::Tag::Package if found.
β sub_line
Parse the declaration of a subroutine, returning a Perl::Tags::Tag::Sub if found.
π use_constant
Parse a use constant directive. π
π¦ use_line
Parse a use, require, and also a use_ok line (from Test::More). It uses a dummy tag β Perl::Tags::Tag::Recurse β to do so. Sneaky but slay. π
π label_line
Parse label declaration.
And that's the whole page, bestie β no notes, no crumbs. This was perl v5.42.0, dated 2025-07-25, and it's Perl::Tags::Naive(3) signing off. Go tag something pretty. πβ¨π
π¦ where this page comes from
- fedora 43: perl-Perl-Tags 0.32-32.fc43 Β· ( GPL-1.0-or-later OR Artistic-1.0-Perl ) OR Vim
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms