Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: POD Meditation?

by JavaFan (Canon)
on Apr 27, 2012 at 20:40 UTC ( #967716=note: print w/replies, xml ) Need Help??

in reply to POD Meditation?

It's code that is tricking all the POD parsers. See, in your code snippet, there is no POD. POD section are defined as to start with the a '=' (followed by a letter) at the beginning of a line, when perl expects a new statement. But here, at the moment of =pod, perl isn't expecting a new statement. In fact, it's busy finding the end of a here document -- whose end is =cut.

So, what's happening here is that:

=pod This module uses the following constants: bang_eth => 1 biff => 2 krunch => 3
is a here document (it starts with a blank line above =pod, and ends with a blank line), with =cut as terminator. The rest is just parsing this string.

Why does it appear in the documentation? Because POD parsers actually don't parse POD. They parse anything between ^=\w and ^=cut, without looking at context, assuming to capture all the POD (and nothing but the POD). Most of the time, this heuristic works well, but as with all heuristics, it sometimes will break down, and someone will (a)buse it.

Replies are listed 'Best First'.
Re^2: POD Meditation?
by temporal (Pilgrim) on Apr 27, 2012 at 20:58 UTC

    Wow, that is pretty neat. So the here document (creatively!) grabs the info in the POD for the perl interpreter, while POD parsers will just see the POD block. Allowing you to have a single point of change for those values.

    Thanks, JavaFan!

    Fun note, this code also plays holy hell with the syntax highlighter in my IDE.

    Strange things are afoot at the Circle-K.
      Except that there isn't any POD... ;-) It's the POD parsers that think there's POD hiding inside a string (here doc).

      Fun note, this code also plays holy hell with the syntax highlighter in my IDE.
      I've never bothered with syntax highlighters, and your remark doesn't convince me I was wrong ;-)
        > Except that there isn't any POD...

        Where do you get your definition for POD from?

        Perl and POD are two different languages which can be intermingled somehow.

      • POD is what the POD-parser matches, and the input doesn't have to be a perl-source anyway.
      • And the Perl-parser doesn't know much about POD-syntax, it basically ignores any blocks between lines starting with a new statement beginning with "=" and followed by at least one word and finished by '=cut'.

        This ignored block doesn't need to be valid POD:

        > perl print "x"; =bala bala blaa asas =cut print "x"
        And the code surrounding POD doesn't need to be Perl.

        Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967716]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2018-06-20 19:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.