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.