Perl::Tags::Naive(3)

πŸ“¦
version 0.32 Β· 2 versions
, in fedora 43

πŸ’– 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