I am putting the finishing touches on a cpan module. I'd like the module to have both a CLI and to be able to be called from within a script. I would like to integrate Getopt::Args with the script if at all possible but I'm not having any luck figuring out how I might accomplish this. From within a script, I am calling an exported function called anki_import and it is called with the name of a file and other args like so:
use Anki::Import; anki_import(<filename>, [--other, --args]);
From the command line, I'd like to be able to invoke the script with something like this: anki_import filename.txt --verbose
I'd like to have Getopt::Args or some similar module process arguments when calling the script from another script or from the command line. Hopefully this is clear. If not, this demonstrates my (failed) attempt at doing this:
package Anki::Import ; use strict; use warnings; use Path::Tiny; use Getopt::Args; use Log::Log4perl::Shortcuts qw(:all); use Exporter qw(import); our @EXPORT = qw(anki_import); # attempt to use Getop::Args opt verbose => ( isa => 'Bool', alias => 'v', comment => 'provide details on progress of Anki::Import' ); my $ref = optargs; <snip> sub anki_import { my $file = shift; # attempt to use Getopt::Args $ref variable to set up log levels if ($ref->{verbose}) { set_log_level('info'); } else { set_log_level('error'); } <snip> }
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to SOLVED: Processing arguments from command line or a script by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |