The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Perl::Tags::Naive

A naive implementation. That is to say, it's based on the classic pltags.pl script distributed with Perl, which is by and large a better bet than the results produced by ctags. But a "better" approach may be to integrate this with PPI.

Subclassing

See TodoTagger in the t/ directory of the distribution for a fully working example (tested in <t/02_subclass.t>). You may want to reuse parsers in the ::Naive package, or use all of the existing parsers and add your own.

    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
    }

Because ::Naive uses can('parser') instead of \&parser, you can just override a particular parser by redefining in the subclass.

get_tags_for_file

::Naive uses 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 registred by the tagger.

get_parsers

The following parsers are defined by this module.

trim

A filter rather than a parser, removes whitespace and comments.

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). Uses a dummy tag (Perl::Tags::Tag::Recurse to do so).

label_line

Parse label declaration