The way I've done it is to subclass Pod::Simple::PullParser, and override get_token like this...

use strict; use warnings; use Data::Dumper (); { package Local::MyPodParser; use base "Pod::Simple::PullParser"; sub get_token { my $self = shift; my $token = $self->SUPER::get_token(@_); # do something with the token print Data::Dumper::Dumper($token); return $token; } } my $parser = "Local::MyPodParser"->new; $parser->parse_file("somefile.pod");

Take a look at TOBYINK::Pod::HTML::Helper which subclasses Pod::Simple::HTML (which is itself a subclass of Pod::Simple::PullParser) to process =for highlighter ... sections.

The one annoyance you might notice is that Pod::Simple::PullParser has a _get_titled_section method that fast-forwards and rewinds the stream of tokens occasionally. The way I've coped with that is to wrap _get_titled_section, setting $self->{_in_get_titled_section} = 1 at the start and delete $self->{_in_get_titled_section} at the end, to act as an indicator of whether we're currently inside that method. Then within my get_token, I only do my processing when we're not inside _get_titled_section.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

In reply to Re: Pod: Need to parse from =begin ... =end blocks by tobyink
in thread Pod: Need to parse from =begin ... =end blocks by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.