The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

runpm - Run Perl module as a command-line application

VERSION

version 0.36

SYNOPSIS

From command-line:

 % runpm Foo::Bar

Or save this in foobar somewhere in PATH:

 #!/bin/bash
 export PERL_RUNPM_PROG=`basename $0`
 runpm Foo::Bar

You can now do:

 % foobar --help; # show help

 % foobar --list; # list all subcommands, which are subroutines in Foo::Bar

 % foobar sub1 --arg1 ... --arg2 ...; # execute sub1

 % foobar --yaml sub1 ...; # execute sub1 and return output as YAML

 % foobar --help sub1; # show help usage for sub1

 % foobar --version

 % complete -C foobar foobar
 % foobar <TAB>; # tab completion will now work

DESCRIPTION

One of the lazy ways of writing a command-line application is by not writing it. You just write your module functions, following a few conventions outlined in Sub::Spec. Later you can "export" your module as a command-line application with runpm and get these features for free: options parsing, --help (including for each subroutine), output formatting, even bash completion.

To make bash completion work, you need to install Sub::Spec::BashComplete first.

runpm calls Sub::Spec::CmdLine's run() under the hood.

Currently runpm offers little options, it's just a quick way to run your module. For more customization (e.g. only export some functions, rename subcommands, run two or more modules, etc), write a wrapper script for run() directly.

SEE ALSO

Sub::Spec

Sub::Spec::CmdLine

A few applications using Sub::Spec::CmdLine: File::RsyBak (the rsybak command), Git::Bunch (the gitbunch command).

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.