How to create POD and use pod2usage in perl?

I want to create a POD for my own command and display the syntax for this using the pod2usage () function.

Can someone give me a simple example?

Regards, Anandan

+5
source share
2 answers

I usually do this with Getopt :: Long along with Pod :: Usage . (I got this habit after reading the tutorial on the PerlMonks website, so here's a link to it .) It looks something like this:

use Getopt::Long;
use Pod::Usage;

my( $opt_help, $opt_man, $opt_full, $opt_admins, $opt_choose, $opt_createdb, );

GetOptions(
    'help!'                 =>      \$opt_help,
    'man!'                  =>      \$opt_man,
    'full!'                 =>      \$opt_full,
    'admin|admins!'         =>      \$opt_admins,
    'choose|select|c=s'     =>      \$opt_choose,
    'createdb!'             =>      \$opt_createdb,
)
  or pod2usage( "Try '$0 --help' for more information." );

pod2usage( -verbose => 1 ) if $opt_help;
pod2usage( -verbose => 2 ) if $opt_man;

In this example, parameters other than $opt_manand $opt_helpare not relevant to you. I just copied the top of the random script that I had here.

POD. , POD.

. OP NAME . GetOptions. 'name' => \$opt_name. :

pod2usage(-verbose => 99, -sections => "NAME") if $opt_name;

99 - : . . Pod::Usage -sections. , -sections () , .

+15

perlpod manpage . Pod2usage .

+4

All Articles