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:

  1. I'm writing the same thing twice. Oh the shame!
  2. The help text is an unformatted string. I'd really like to have it look and behave like the oh-so-lovely output of pod2usage.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.