Re: Pod::Simple can treat binary as pod due to liberal/inconsistent regexp patterns

[email protected] (Karl Williamson) Thu, 08 Jan 2015 12:03:40 -0700
Newsgroups perl.pod-people
Message-ID <[email protected]>
On 01/08/2015 11:17 AM, Randy Stauner wrote:
>     > IIRC the first "liberal" rx is to detect start of POD just like the Perl (language) parser does, i.e. it pauses parsing for instructions until the next =cut
>
>     Oh. Can someone dig into the Perl parser and confirm this?
>
>     > I think POD parsers should do the same.
>
>     My suspicion is that, even if that’s true, the Parser ignores
>     everything in a __DATA__ or __END__ block.
>
>
> Here is an example I worked up when writing test for metacpan:
> Everything after __DATA__ is data, but the pod parser will also find pod
> if it's there
> https://gist.github.com/rwstauner/98f97e6cd64c972d9b71


I don't understand the parser very well, but if someone wants a crack at 
it, here is the only portion of it that sets to being in pod.  The 
context is that the first character on the line is an "=", and tmp holds 
the character that follows that "=".  I think 's' points to the input 
starting at tmp, so that tmp == *s:

	    if (PL_expect == XSTATE && isALPHA(tmp) &&
		(s == PL_linestart+1 || s[-2] == '\n') )
             {
                 if ((PL_in_eval && !PL_rsfp && !PL_parser->filtered)
                     || PL_lex_state != LEX_NORMAL) {
                     d = PL_bufend;
                     while (s < d) {
                         if (*s++ == '\n') {
                             incline(s);
                             if (strnEQ(s,"=cut",4)) {
                                 s = strchr(s,'\n');
                                 if (s)
                                     s++;
                                 else
                                     s = d;
                                 incline(s);
                                 goto retry;
                             }
                         }
                     }
                     goto retry;
                 }
                 s = PL_bufend;
                 PL_parser->in_pod = 1;
                 goto retry;
             }