Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Question regardin Pod::Simple usage

by jmcnamara (Monsignor)
on Oct 28, 2004 at 15:58 UTC ( [id://403423]=note: print w/replies, xml ) Need Help??


in reply to Question regardin Pod::Simple usage


When I read your previous node I started working on a Pod::Simple example since that is currently my Pod weapon of choice. However, I couldn't find an easy way to make it do what you wanted. So instead I turned it around and marked all of the code lines and then removed them from the content.

I think that the Pod::Select example above is more elegant, for this case, but here is the Pod::Simple example for the record:

#!/usr/bin/perl -w package MyParser; use Pod::Simple; @ISA = qw(Pod::Simple); use strict; sub new { my $self = shift->SUPER::new(@_); $self->{_lines} = []; # Add a callback for code lines $self->code_handler ( sub { my $line_num = $_[1]; my $parser = $_[2]; # Replace code lines with undef. $parser->{_lines}->[$line_num -1] = undef; return; } ); return $self; } # # Override parse_lines to store a copy of the input. # sub parse_lines { my $self = shift; push @{$self->{_lines}}, @_; $self->SUPER::parse_lines(@_); } # # Filter out the undef lines that replace the code lines. # sub pod_only { my $self = shift; my @pod = grep {defined} @{$self->{_lines}}; print {$self->{'output_fh'}} @pod; return @pod; } 1; # # Back to our scheduled program. # package main; use strict; my $pod; my $parser =MyParser->new(); $parser->parse_file(*DATA); $parser->output_string(\$pod); $parser->pod_only(); print $pod; __DATA__ # Some code my $foo = 'bar'; =head1 This is a B<heading> This is a paragraph. This is a verbatim section. This is I<B<another>> paragraph =cut

--
John.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://403423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found