Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Synopsis CPAN distribution.

Report information
The Basics
Id: 51534
Status: resolved
Priority: 0/
Queue: Test-Synopsis

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: end =for at blank line
Date: Sun, 15 Nov 2009 09:09:43 +1100
To: bug-Test-Synopsis [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Nosing around Test::Synopsis 0.02, I noticed that when picking out its =for test_synopsis it seems to go through to the next "=" directive, where I think the pod spec has "=for" normally extending only to the next blank line. I struck this trying to put an =for immediately before the code, like =head1 SYNOPSIS =for test_synopsis my ($some,$thing); use my::thing FOO => $some+$thing; For uniformity it'd be good if =for test_synopsis was taken the same way as the pod parsers. Using Pod::Parser itself (included in perl 5.6 and up anyway) could be the easiest way to be most compatible. That might make it possible to recognise an =begin through =end section too, in case someone wanted a big chunk of extra code.
Subject: Re: [rt.cpan.org #51534] end =for at blank line
Date: Sat, 14 Nov 2009 14:30:25 -0800
To: bug-Test-Synopsis [...] rt.cpan.org
From: Tatsuhiko Miyagawa <miyagawa [...] gmail.com>
Can you provide a patch? It's on my github http://github.com/miyagawa/test-synopsis On Sat, Nov 14, 2009 at 2:11 PM, Kevin Ryde via RT <bug-Test-Synopsis@rt.cpan.org> wrote: Show quoted text
> Sat Nov 14 17:11:17 2009: Request 51534 was acted upon. > Transaction: Ticket created by user42@zip.com.au >       Queue: Test-Synopsis >     Subject: end =for at blank line >   Broken in: (no value) >    Severity: (no value) >       Owner: Nobody >  Requestors: user42@zip.com.au >      Status: new >  Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=51534 > > > > Nosing around Test::Synopsis 0.02, I noticed that when picking out its > =for test_synopsis it seems to go through to the next "=" directive, > where I think the pod spec has "=for" normally extending only to the > next blank line. > > I struck this trying to put an =for immediately before the code, like > >    =head1 SYNOPSIS > >    =for test_synopsis my ($some,$thing); > >     use my::thing FOO => $some+$thing; > > For uniformity it'd be good if =for test_synopsis was taken the same way > as the pod parsers.  Using Pod::Parser itself (included in perl 5.6 and > up anyway) could be the easiest way to be most compatible.  That might > make it possible to recognise an =begin through =end section too, in > case someone wanted a big chunk of extra code. > >
-- Tatsuhiko Miyagawa
Subject: Re: [rt.cpan.org #51534] end =for at blank line
Date: Tue, 17 Nov 2009 09:28:31 +1100
To: bug-Test-Synopsis [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"miyagawa@gmail.com via RT" <bug-Test-Synopsis@rt.cpan.org> writes: Show quoted text
> > Can you provide a patch?
I got to the few lines below. It seems a slightly big chunk of code for a little parse, but should do things like cooperate with unrelated =for/=begin directives in ways that would be hard with just regexps.
diff --git a/lib/Test/Synopsis.pm b/lib/Test/Synopsis.pm index fedeacd..eb1495d 100644 --- a/lib/Test/Synopsis.pm +++ b/lib/Test/Synopsis.pm @@ -42,16 +42,72 @@ sub _compile { sub extract_synopsis { my $file = shift; - my $content = do { - local $/; - open my $fh, "<", $file or die "$file: $!"; - <$fh>; - }; + my $parser = Test::Synopsis::Parser->new; + $parser->parse_from_file ($file); + return ($parser->{'test_synopsis'}, + $parser->{'test_synopsis_linenum'}, + @{$parser->{'test_synopsis_options'}}); +} + - my $code = ($content =~ m/^=head1\s+SYNOPSIS(.+?)^=head1/ms)[0]; - my $line = ($` || '') =~ tr/\n/\n/; +package Test::Synopsis::Parser; +use base 'Pod::Parser'; - return $code, $line-1, ($content =~ m/^=for\s+test_synopsis\s+(.+?)^=/msg); +sub new { + my $class = shift; + return $class->SUPER::new (@_, + within_begin => '', + test_synopsis_options => []); +} +sub command { + my $self = shift; + my ($command, $text, $linenum, $paraobj) = @_; + ## print "command: '$command' -- '$text'\n"; + + if ($command eq 'for') { + if ($text =~ /^test_synopsis\s+(.*)/s) { + push @{$self->{'test_synopsis_options'}}, $1; + } + } elsif ($command eq 'begin') { + $self->{'within_begin'} = $text; + } elsif ($command eq 'end') { + $self->{'within_begin'} = ''; + } elsif ($command eq 'pod') { + # resuming pod, retain begin/end/synopsis state + } else { + # Synopsis is "=head1 SYNOPSIS" through to next command other than + # the above "=for", "=begin", "=end", "=pod". This means + # * "=for" directives for other programs are skipped + # (eg. HTML::Scrubber) + # * "=begin" to "=end" for other program are skipped + # (eg. Date::Simple) + # * "=cut" to "=pod" actual code is skipped (perhaps unlikely in + # practice) + # + # Could think about not stopping at "=head2" etc subsections of a + # synopsis, but a synopsis with subsections usually means different + # sample bits meant for different places and so probably won't + # actually run. + # + $self->{'within_synopsis'} + = ($command eq 'head1' && $text =~ /^SYNOPSIS\s*$/); + } + return ''; +} +sub verbatim { + my ($self, $text, $linenum, $paraobj) = @_; + if ($self->{'within_begin'} =~ /^test_synopsis\b/) { + push @{$self->{'test_synopsis_options'}}, $text; + + } elsif ($self->{'within_synopsis'} && ! $self->{'within_begin'}) { + $self->{'test_synopsis_linenum'} ||= $linenum; # first occurance + $self->{'test_synopsis'} .= $text; + } + return ''; +} +sub textblock { + # ignore text paragraphs, only take "verbatim" blocks to be code + return ''; } 1;
Thanks so much for the patch—works great. Pushed the fix to the repo (zoffix/fix-all-RT-bugs branch). Will make a release to CPAN soon. -- Cheers, ZZ [ https://metacpan.org/author/ZOFFIX ]
Resolved in version 0.7 which is now on CPAN: https://metacpan.org/release/ZOFFIX/Test-Synopsis-0.07 -- Cheers, ZZ [ https://metacpan.org/author/ZOFFIX ]