I am writing a shell with Term::Shell, which handles the guts I don't want to (read: can't) deal with. One such bit of guts is implementing `help $command` - this is done by defining sub help_command { return 'your help text'; }
However, since I'm writing Pod anyways, I end up with two problems:
My thinking is that in help_command(), I could extract the appropriate section of Pod from the file with Pod::Select, then format it with Pod::Text::Termcap. This would give me a single string that could be returned. I've got the formatting done, but extracting the Pod section is failing.
How can I extract the text of a section of Pod and save it to a scalar so I can massage it further? Alternatively, how can I get pod2usage to a) show only a section of Pod and b) actually work from inside Term::Shell?
=head1 delete Delete a wiki page: delete "Main Page" "for teh lulz" =cut sub run_delete { my $o = shift; my $page = shift; my $summary = shift || 'Vandalism'; if (@_ > 0) { my $abort = prompt('y', 'Abort?', qq{Did you mean to delete [[ +$page]] with reason "$summary"?}, 'y'); return 1 if $abort; } my $success = $u->delete($page, $summary); if ($success) { print "Deletion successful\n"; } else { print "Deletion failed:\n" . " $u->{'error'}->{'details'}\n"; } } sub smry_delete { return 'delete a page'; } sub help_delete { # There has to be some way of getting this Pod fragment # from the file directly. Also, if we put it here, # Pod::Weaver won't touch the file, and that's disappointing. my $pod = <<'END'; =head1 Delete a wiki page This will delete a page on the wiki you're currently using: delete "Main Page" "for teh lulz" Make sure you quote your input correctly. =cut END my $pod_parser = Pod::Text::Termcap->new( width => 72, utf8 => 1, ); my $rendered_pod; $pod_parser->output_string(\$rendered_pod); $pod_parser->parse_string_document($pod); return $rendered_pod; }
In reply to Extracting and formatting Pod sections by Mike.lifeguard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |