Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

You all might know programs like git, svn or mp4box where you can ask for a general help and specific help like:

svn help commit

I've started today a script which also has several commands like svn has and so I'd like to have a similar way to present help, but I can't figure out how to utilize Pod::Usage for this. I have to add that unfortunately the Pod::Usage version on the target system is at V1.33 :(

Update: My initial idea was to have one POD for each of the commands.

Does anyone have any useful tipps for me?

Update #2 Thanks to dasgar I think I found a way:

I defined a sub to which I pass an option list like pod2usage expects. The option "-pod" defines the name of the pod I want, while the rest is simply passed on to pod2usage.

#!/usr/bin/perl use strict; use warnings; use Pod::Usage; pod( -pod => 'test', -verbose => 2 ); sub pod { my(%options)= @_; my $pod_text; SWITCH: for ($options{-pod}) { /^main$/ && do { $pod_text=<<'POD'; =head1 NAME Main =head1 SYNOPSIS main.pl [options] =head1 DESCRIPTION This is main =cut POD last SWITCH; }; /^test$/ && do { $pod_text=<<'POD'; =head1 NAME Test =head1 SYNOPSIS Test.pl [options] =head1 DESCRIPTION This is Test =cut POD last SWITCH; }; return; } delete $options{-pod}; delete $options{-input}; open my $pod_file, '<', \$pod_text; pod2usage( -input => $pod_file, %options ) }

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: Pod::Usage - Can I have multiple Pods in one script?
by VinsWorldcom (Prior) on Jan 19, 2016 at 21:57 UTC

    I've done *something* like that by using Getopt::Long and Pod::Usage. Basically, when '--help' is specified with other key command line switches, the user gets the appropriate POD section. Otherwise, they can use '--man' to get the full monty.

    use strict; use warnings; use Getopt::Long qw(:config no_ignore_case); use Pod::Usage; my %opt; my ( $opt_help, $opt_man, $opt_versions ); GetOptions( [...] 'P|password=s' => \$opt{Pass}, [...] 's|snmp=s' => \$opt{snmp}, [...] 'username=s' => \$opt{user}, [...] 'help!' => \$opt_help, 'man!' => \$opt_man, 'versions!' => \$opt_versions ) or pod2usage( -verbose => 0 ); if ( defined $opt_help ) { pod2usage( -verbose => 99, -sections => "OPTIONS/PASSWORD MODE" ) if defined $opt{Pass}; pod2usage( -verbose => 99, -sections => "OPTIONS/SNMP MODE" ) if defined $opt{snmp}; pod2usage( -verbose => 99, -sections => "OPTIONS/TELNET SSH MODE" +) if ( defined $opt{user} or defined $opt{pass} ); } pod2usage( -verbose => 1 ) if defined $opt_help; pod2usage( -verbose => 2 ) if defined $opt_man; [...] __END__ =head1 NAME [...] =head1 SYNOPSIS [...] =head1 DESCRIPTION [...] =head1 OPTIONS [...] =head2 PASSWORD MODE To activate B<Password Mode>, use the -P option. [...] =head2 SNMP MODE To activate B<SNMP Mode>, use the -s option. [...] =head2 TELNET SSH MODE To activate B<Telnet Mode>, use the -p option without -s. [...] =cut

      I also tried that, but it unfortunately failed :( Subsections seemed to be unsupported in 1.33

      Update: I must have done something wrong. Subsections are supported.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Pod::Usage - Can I have multiple Pods in one script?
by Mr. Muskrat (Canon) on Jan 19, 2016 at 21:55 UTC

    I tried but failed to quickly find the docs for Pod::Usage version 1.33. If it supports -sections then I'd do something like this:

    # get your command arguments and conditionally set $help_command # from your example: svn help commit # $help_command should contain 'commit' if (defined $help_command) { pod2usage(-verbose => 99, -sections => [ $help_command ] ); } else { pod2usage( ... ); # normal usage of help without $help_command defin +ed }

    Don't forget to define a 'commit' section in your POD.

      Sections are supported, but only main sections, no subsections.

      Update: I must have done something wrong. Subsections are supported.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Pod::Usage - Can I have multiple Pods in one script?
by dasgar (Priest) on Jan 19, 2016 at 22:08 UTC

    I'm not sure that I understand what you're trying to do. Based on the thread title, it sounds like you want to use multiple POD files with Pod::Usage. To do that, take a look at the CAVEATS section of the Pod::Usage documentation. It shows how to provide a file to Pod::Usage. I downloaded the tarball for Pod::Usage version 1.33 and the same information is in the caveat section of it's documentation as well.

      Thanks for pointing me to that. It sounds like an interesting idea although I'd have to put the documentation into different files then.

      Update: See Update #2 in the original post. I solved this by putting the PODs into a scalar and using in-memory files.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: [Solved] Pod::Usage - Can I have multiple Pods in one script?
by thomas895 (Deacon) on Jan 20, 2016 at 22:47 UTC

    Can you bundle a newer version with your dist?

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."

      I think it isn't worth the effort, but a valid idea. Thanks.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e