SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
Modern Getopt for
Command Line Processing
         Nick Patch

          YAPC::NA

        28 June 2011
"Getting command line options and
dealing with them is a colossal pain,
 and every module that does it sucks
        and offends someone."

                — Ricardo Signes (rjbs)
Getopt::Abridged Getopt::ArgvFile Getopt::AsDocumented
 Getopt::Attribute Getopt::AutoConf Getopt::Awesome Getopt::Base
   Getopt::CallingName Getopt::Casual Getopt::Chain Getopt::Clade
      Getopt::Compact Getopt::Compact::WithCmd Getopt::Complete
   Getopt::constant Getopt::Declare Getopt::Easy Getopt::Euclid
    Getopt::EvaP Getopt::ExPar Getopt::Fancy Getopt::FileConfig
 Getopt::Flex Getopt::Function Getopt::GetArgs Getopt::GUI::Long
   Getopt::Helpful Getopt::Inherited Getopt::Janus Getopt::Lazy
          Getopt::LL Getopt::Long Getopt::Long::Descriptive
 Getopt::Long::DescriptivePod Getopt::Long::GUI Getopt::LongUsage
 Getopt::Lucid Getopt::Mixed Getopt::Mixed::Help Getopt::Modular
     Getopt::OO Getopt::Param Getopt::Param::Tiny Getopt::Plus
           Getopt::Regex Getopt::Simple Getopt::Std::Strict
 Getopt::Std::WithCheck Getopt::Tabular Getopt::Tiny Getopt::Tree
Getopt::Usaginator Getopt::Whatever Getopt::WonderBra Getopt::XML
      Getopt::Yagow Getopt_Auto CBSSports::Getopt CGI::Getopt
MooseX::Getopt MooseX::Getopt::Defanged MouseX::Getopt Tk::Getopt
that's 63 Getopt modules
Getopt::Easy or Getopt::Simple ?
Getopt::Tiny or Getopt::Compact ?
maybe Getopt::Awesome ?
Getopt::WonderBra ?!
Getopt::WonderBra ?!

"Lift and Separate Command Line Options"
dependents

454   Getopt::Long
 64   MooseX::Getopt
 28   Getopt::Long::Descriptive
 18   Getopt::ArgvFile
 11   Getopt::Std::Strict
 10   Getopt::Lucid
  7   Getopt::Euclid
  5   Getopt::Attribute
  5   Getopt::Mixed
  5   Getopt::Usaginator
minus same authors

446   Getopt::Long
 62   MooseX::Getopt
 19   Getopt::Long::Descriptive
 17   Getopt::ArgvFile
  7   Getopt::Euclid
  7   Getopt::Lucid
  5   Getopt::Mixed
plus first release date

446   Getopt::Long                1995
 62   MooseX::Getopt              2007
 19   Getopt::Long::Descriptive   2005
 17   Getopt::ArgvFile            1999
  7   Getopt::Euclid              2005
  7   Getopt::Lucid               2005
  5   Getopt::Mixed               1996
Getopt::Lucid
$ munge --in refuse.log --out allure.json
$ munge --in refuse.log --out allure.json



my $opt = Getopt::Lucid->getopt({
    Param('in'),
    Param('out'),
});
$ munge --in refuse.log --out allure.json



my $opt = Getopt::Lucid->getopt({
    Param('in')->required,
    Param('out')->required,
});
$ munge --in refuse.log --out allure.json



my $opt = Getopt::Lucid->getopt({
    Param('in')->required,
    Param('out')->required,
});

open my $in_fh, '<', $opt->get_in;
open my $out_fh, '>', $opt->get_out;
$ frobnicate --calibrate
$ frobnicate -c
$ frobnicate --calibrate
$ frobnicate -c



my $opt = Getopt::Lucid->getopt({
    Switch('calibrate|c'),
});
$ frobnicate --calibrate
$ frobnicate -c



my $opt = Getopt::Lucid->getopt({
    Switch('calibrate|c'),
});

print "Calibrating the frobnicator!n"
    if $opt->get_calibrate;
$ frobnicate --calibrate
$ frobnicate -c

use 5.010;

my $opt = Getopt::Lucid->getopt({
    Switch('calibrate|c'),
});

say 'Calibrating the frobnicator!'
    if $opt->get_calibrate;
$ frobnicate --calibrate
$ frobnicate -c

use 5.010;

my $opt = Getopt::Lucid->getopt({
    Switch('calibrate|c'),
});

say 'Calibrating the frobnicator!'
    if $opt->get_calibrate;

$opt->set_calibrate(0);
$ perlping -v -s 512 4.2.2.2
$ perlping -v -s 512 4.2.2.2



my $opt = Getopt::Lucid->getopt({
    Param('size|s'),
    Param('ttl|t'),
    Switch('verbose|v'),
});
$ perlping -v -s 512 4.2.2.2



my $opt = Getopt::Lucid->getopt({
    Param('size|s')->default(64),
    Param('ttl|t')->default(50),
    Switch('verbose|v'),
});
$ perlping -v -s 512 4.2.2.2



my $opt = Getopt::Lucid->getopt({
    Param('size|s')->default(64),
    Param('ttl|t')->default(50),
    Switch('verbose|v'),
});

my $destination = shift @ARGV;
MooseX::Getopt
MooseX::Getopt
      or
MouseX::Getopt
$ munge --in refuse.log --out allure.json
$ munge --in refuse.log --out allure.json

package File::Munge;
use Moose;
with 'MooseX::Getopt';
$ munge --in refuse.log --out allure.json

package File::Munge;
use Moose;
with 'MooseX::Getopt';

has in => (is => 'rw', isa => 'Str');
has out => (is => 'rw', isa => 'Str');
$ munge --in refuse.log --out allure.json

package File::Munge;
use Moose;
with 'MooseX::Getopt';

has in => (is => 'rw', isa => 'Str', required => 1);
has out => (is => 'rw', isa => 'Str', required => 1);
$ munge --in refuse.log --out allure.json

package File::Munge;
use Moose;
with 'MooseX::Getopt';

has in => (is => 'rw', isa => 'Str', required => 1);
has out => (is => 'rw', isa => 'Str', required => 1);

sub munge {
    my $self = shift;
    open my $in_fh, '<', $self->in;
    open my $out_fh, '>', $self->out;
}
#!/usr/bin/perl
use File::Munge;

my $munger = File::Munge->new_with_options;

$munger->munge;
$ frobnicate --calibrate
$ frobnicate -c
$ frobnicate --calibrate
$ frobnicate -c

has calibrate => (
    is          =>   'rw',
    isa         =>   'Bool',
    traits      =>   ['Getopt'],
    cmd_aliases =>   'c',
);
$ frobnicate --calibrate
$ frobnicate -c

has calibrate => (
    is          =>   'rw',
    isa         =>   'Bool',
    traits      =>   ['Getopt'],
    cmd_aliases =>   'c',
);

sub frob {
    my $self = shift;
    say 'Calibrating the frobnicator!'
        if $self->calibrate;
    $self->calibrate(0);
}
$ perlping -v -s 512 4.2.2.2
$ perlping -v -s 512 4.2.2.2



has size    => (is => 'rw', isa => 'Int');
has ttl     => (is => 'rw', isa => 'Int');
has verbose => (is => 'rw', isa => 'Bool');
$ perlping -v -s 512 4.2.2.2



has size    => (is => 'rw', isa => 'Int', default => 64);
has ttl     => (is => 'rw', isa => 'Int', default => 50);
has verbose => (is => 'rw', isa => 'Bool');
$ perlping -v -s 512 4.2.2.2



has size    => (is => 'rw', isa => 'Int', default => 64);
has ttl     => (is => 'rw', isa => 'Int', default => 50);
has verbose => (is => 'rw', isa => 'Bool');

has _destination => (
    is      => 'rw',
    isa     => 'Str',
    default => sub {
        my $self = shift;
        return shift @{ $self->extra_argv };
    }
);
$ perlping -v -s 512 4.2.2.2

use 5.014;

has size    => (is => 'rw', isa => 'Int', default => 64);
has ttl     => (is => 'rw', isa => 'Int', default => 50);
has verbose => (is => 'rw', isa => 'Bool');

has _destination => (
    is      => 'rw',
    isa     => 'Str',
    default => sub {
        my $self = shift;
        return shift $self->extra_argv;
    }
);
my suggestions
my suggestions

     Getopt::Lucid or
Getopt::Long::Descriptive
    for one-off scripts
my suggestions

        Getopt::Lucid or
   Getopt::Long::Descriptive
       for one-off scripts

MooseX::Getopt or MouseX::Getopt
         for OO projects
my suggestions

        Getopt::Lucid or
   Getopt::Long::Descriptive
       for one-off scripts

MooseX::Getopt or MouseX::Getopt
         for OO projects

  App::Cmd, MooseX::App::Cmd
      or MouseX::App::Cmd
    for command-driven scripts
questions?
slides at:
nickpatch.net

Más contenido relacionado

La actualidad más candente

On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shellsascha_klein
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionIan Barber
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
ZeroMQ Is The Answer: PHP Tek 11 Version
ZeroMQ Is The Answer: PHP Tek 11 VersionZeroMQ Is The Answer: PHP Tek 11 Version
ZeroMQ Is The Answer: PHP Tek 11 VersionIan Barber
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL Tiger2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL TigerAkihiro Okuno
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6Nobuo Danjou
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 

La actualidad más candente (20)

On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shell
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
ZeroMQ Is The Answer: PHP Tek 11 Version
ZeroMQ Is The Answer: PHP Tek 11 VersionZeroMQ Is The Answer: PHP Tek 11 Version
ZeroMQ Is The Answer: PHP Tek 11 Version
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
TRunner
TRunnerTRunner
TRunner
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL Tiger2010/7/31 LTの虎@LL Tiger
2010/7/31 LTの虎@LL Tiger
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 

Destacado

Bildschirmfoto 2015-12-18 um 14.13.16
Bildschirmfoto 2015-12-18 um 14.13.16Bildschirmfoto 2015-12-18 um 14.13.16
Bildschirmfoto 2015-12-18 um 14.13.16Jörg Fessler
 
Dag 06 Kj Co Makers Bm (Voor Diaboek)
Dag 06 Kj Co Makers Bm (Voor Diaboek)Dag 06 Kj Co Makers Bm (Voor Diaboek)
Dag 06 Kj Co Makers Bm (Voor Diaboek)Stipo
 
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...guest36ad53
 
Yogasana Demonstration Dr. Shriniwas Kashalikar
Yogasana Demonstration Dr. Shriniwas KashalikarYogasana Demonstration Dr. Shriniwas Kashalikar
Yogasana Demonstration Dr. Shriniwas Kashalikardrsprasadi
 
Интегрированные коммуникации - модуль 3
Интегрированные коммуникации - модуль 3Интегрированные коммуникации - модуль 3
Интегрированные коммуникации - модуль 3Usanov Aleksey
 
SW5 Impact Report - Semester 1 15-16
SW5 Impact Report - Semester 1 15-16SW5 Impact Report - Semester 1 15-16
SW5 Impact Report - Semester 1 15-16Charlie Freeman
 
Public Relations 2.0, Marcel Olislagers LECTRIC
Public Relations 2.0, Marcel Olislagers LECTRICPublic Relations 2.0, Marcel Olislagers LECTRIC
Public Relations 2.0, Marcel Olislagers LECTRICLECTRIC
 

Destacado (20)

TOR 1
TOR 1TOR 1
TOR 1
 
Materi kakanwil pada acara pentaloka KUB
Materi kakanwil pada acara pentaloka KUBMateri kakanwil pada acara pentaloka KUB
Materi kakanwil pada acara pentaloka KUB
 
Ref FEA
Ref FEARef FEA
Ref FEA
 
Bildschirmfoto 2015-12-18 um 14.13.16
Bildschirmfoto 2015-12-18 um 14.13.16Bildschirmfoto 2015-12-18 um 14.13.16
Bildschirmfoto 2015-12-18 um 14.13.16
 
document-25
document-25document-25
document-25
 
Dag 06 Kj Co Makers Bm (Voor Diaboek)
Dag 06 Kj Co Makers Bm (Voor Diaboek)Dag 06 Kj Co Makers Bm (Voor Diaboek)
Dag 06 Kj Co Makers Bm (Voor Diaboek)
 
Manos Pintadas
Manos PintadasManos Pintadas
Manos Pintadas
 
Callobre
CallobreCallobre
Callobre
 
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...
4ª Sessão - O Modelo de Auto-Avaliação das Bibliotecas Escolares: metodologia...
 
Alfabeto
AlfabetoAlfabeto
Alfabeto
 
Fit Fuel
Fit FuelFit Fuel
Fit Fuel
 
Tantra Nepal
Tantra NepalTantra Nepal
Tantra Nepal
 
Yogasana Demonstration Dr. Shriniwas Kashalikar
Yogasana Demonstration Dr. Shriniwas KashalikarYogasana Demonstration Dr. Shriniwas Kashalikar
Yogasana Demonstration Dr. Shriniwas Kashalikar
 
.
..
.
 
Интегрированные коммуникации - модуль 3
Интегрированные коммуникации - модуль 3Интегрированные коммуникации - модуль 3
Интегрированные коммуникации - модуль 3
 
document-24
document-24document-24
document-24
 
intelaql club
intelaql clubintelaql club
intelaql club
 
SW5 Impact Report - Semester 1 15-16
SW5 Impact Report - Semester 1 15-16SW5 Impact Report - Semester 1 15-16
SW5 Impact Report - Semester 1 15-16
 
Public Relations 2.0, Marcel Olislagers LECTRIC
Public Relations 2.0, Marcel Olislagers LECTRICPublic Relations 2.0, Marcel Olislagers LECTRIC
Public Relations 2.0, Marcel Olislagers LECTRIC
 
Plantão obst
Plantão obstPlantão obst
Plantão obst
 

Similar a Modern Getopt for Command Line Processing in Perl

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsMark Baker
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
Api Design
Api DesignApi Design
Api Designsartak
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략Jeen Lee
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Joseph Scott
 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst TipsJay Shirley
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Anatoly Sharifulin
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
Perl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReducePerl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReducePedro Figueiredo
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
 

Similar a Modern Getopt for Command Line Processing in Perl (20)

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 Generators
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Api Design
Api DesignApi Design
Api Design
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Groovy
GroovyGroovy
Groovy
 
Perl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReducePerl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReduce
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 

Último

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Modern Getopt for Command Line Processing in Perl

  • 1. Modern Getopt for Command Line Processing Nick Patch YAPC::NA 28 June 2011
  • 2. "Getting command line options and dealing with them is a colossal pain, and every module that does it sucks and offends someone." — Ricardo Signes (rjbs)
  • 3. Getopt::Abridged Getopt::ArgvFile Getopt::AsDocumented Getopt::Attribute Getopt::AutoConf Getopt::Awesome Getopt::Base Getopt::CallingName Getopt::Casual Getopt::Chain Getopt::Clade Getopt::Compact Getopt::Compact::WithCmd Getopt::Complete Getopt::constant Getopt::Declare Getopt::Easy Getopt::Euclid Getopt::EvaP Getopt::ExPar Getopt::Fancy Getopt::FileConfig Getopt::Flex Getopt::Function Getopt::GetArgs Getopt::GUI::Long Getopt::Helpful Getopt::Inherited Getopt::Janus Getopt::Lazy Getopt::LL Getopt::Long Getopt::Long::Descriptive Getopt::Long::DescriptivePod Getopt::Long::GUI Getopt::LongUsage Getopt::Lucid Getopt::Mixed Getopt::Mixed::Help Getopt::Modular Getopt::OO Getopt::Param Getopt::Param::Tiny Getopt::Plus Getopt::Regex Getopt::Simple Getopt::Std::Strict Getopt::Std::WithCheck Getopt::Tabular Getopt::Tiny Getopt::Tree Getopt::Usaginator Getopt::Whatever Getopt::WonderBra Getopt::XML Getopt::Yagow Getopt_Auto CBSSports::Getopt CGI::Getopt MooseX::Getopt MooseX::Getopt::Defanged MouseX::Getopt Tk::Getopt
  • 9. Getopt::WonderBra ?! "Lift and Separate Command Line Options"
  • 10. dependents 454 Getopt::Long 64 MooseX::Getopt 28 Getopt::Long::Descriptive 18 Getopt::ArgvFile 11 Getopt::Std::Strict 10 Getopt::Lucid 7 Getopt::Euclid 5 Getopt::Attribute 5 Getopt::Mixed 5 Getopt::Usaginator
  • 11. minus same authors 446 Getopt::Long 62 MooseX::Getopt 19 Getopt::Long::Descriptive 17 Getopt::ArgvFile 7 Getopt::Euclid 7 Getopt::Lucid 5 Getopt::Mixed
  • 12. plus first release date 446 Getopt::Long 1995 62 MooseX::Getopt 2007 19 Getopt::Long::Descriptive 2005 17 Getopt::ArgvFile 1999 7 Getopt::Euclid 2005 7 Getopt::Lucid 2005 5 Getopt::Mixed 1996
  • 14. $ munge --in refuse.log --out allure.json
  • 15. $ munge --in refuse.log --out allure.json my $opt = Getopt::Lucid->getopt({ Param('in'), Param('out'), });
  • 16. $ munge --in refuse.log --out allure.json my $opt = Getopt::Lucid->getopt({ Param('in')->required, Param('out')->required, });
  • 17. $ munge --in refuse.log --out allure.json my $opt = Getopt::Lucid->getopt({ Param('in')->required, Param('out')->required, }); open my $in_fh, '<', $opt->get_in; open my $out_fh, '>', $opt->get_out;
  • 18. $ frobnicate --calibrate $ frobnicate -c
  • 19. $ frobnicate --calibrate $ frobnicate -c my $opt = Getopt::Lucid->getopt({ Switch('calibrate|c'), });
  • 20. $ frobnicate --calibrate $ frobnicate -c my $opt = Getopt::Lucid->getopt({ Switch('calibrate|c'), }); print "Calibrating the frobnicator!n" if $opt->get_calibrate;
  • 21. $ frobnicate --calibrate $ frobnicate -c use 5.010; my $opt = Getopt::Lucid->getopt({ Switch('calibrate|c'), }); say 'Calibrating the frobnicator!' if $opt->get_calibrate;
  • 22. $ frobnicate --calibrate $ frobnicate -c use 5.010; my $opt = Getopt::Lucid->getopt({ Switch('calibrate|c'), }); say 'Calibrating the frobnicator!' if $opt->get_calibrate; $opt->set_calibrate(0);
  • 23. $ perlping -v -s 512 4.2.2.2
  • 24. $ perlping -v -s 512 4.2.2.2 my $opt = Getopt::Lucid->getopt({ Param('size|s'), Param('ttl|t'), Switch('verbose|v'), });
  • 25. $ perlping -v -s 512 4.2.2.2 my $opt = Getopt::Lucid->getopt({ Param('size|s')->default(64), Param('ttl|t')->default(50), Switch('verbose|v'), });
  • 26. $ perlping -v -s 512 4.2.2.2 my $opt = Getopt::Lucid->getopt({ Param('size|s')->default(64), Param('ttl|t')->default(50), Switch('verbose|v'), }); my $destination = shift @ARGV;
  • 28. MooseX::Getopt or MouseX::Getopt
  • 29. $ munge --in refuse.log --out allure.json
  • 30. $ munge --in refuse.log --out allure.json package File::Munge; use Moose; with 'MooseX::Getopt';
  • 31. $ munge --in refuse.log --out allure.json package File::Munge; use Moose; with 'MooseX::Getopt'; has in => (is => 'rw', isa => 'Str'); has out => (is => 'rw', isa => 'Str');
  • 32. $ munge --in refuse.log --out allure.json package File::Munge; use Moose; with 'MooseX::Getopt'; has in => (is => 'rw', isa => 'Str', required => 1); has out => (is => 'rw', isa => 'Str', required => 1);
  • 33. $ munge --in refuse.log --out allure.json package File::Munge; use Moose; with 'MooseX::Getopt'; has in => (is => 'rw', isa => 'Str', required => 1); has out => (is => 'rw', isa => 'Str', required => 1); sub munge { my $self = shift; open my $in_fh, '<', $self->in; open my $out_fh, '>', $self->out; }
  • 34. #!/usr/bin/perl use File::Munge; my $munger = File::Munge->new_with_options; $munger->munge;
  • 35. $ frobnicate --calibrate $ frobnicate -c
  • 36. $ frobnicate --calibrate $ frobnicate -c has calibrate => ( is => 'rw', isa => 'Bool', traits => ['Getopt'], cmd_aliases => 'c', );
  • 37. $ frobnicate --calibrate $ frobnicate -c has calibrate => ( is => 'rw', isa => 'Bool', traits => ['Getopt'], cmd_aliases => 'c', ); sub frob { my $self = shift; say 'Calibrating the frobnicator!' if $self->calibrate; $self->calibrate(0); }
  • 38. $ perlping -v -s 512 4.2.2.2
  • 39. $ perlping -v -s 512 4.2.2.2 has size => (is => 'rw', isa => 'Int'); has ttl => (is => 'rw', isa => 'Int'); has verbose => (is => 'rw', isa => 'Bool');
  • 40. $ perlping -v -s 512 4.2.2.2 has size => (is => 'rw', isa => 'Int', default => 64); has ttl => (is => 'rw', isa => 'Int', default => 50); has verbose => (is => 'rw', isa => 'Bool');
  • 41. $ perlping -v -s 512 4.2.2.2 has size => (is => 'rw', isa => 'Int', default => 64); has ttl => (is => 'rw', isa => 'Int', default => 50); has verbose => (is => 'rw', isa => 'Bool'); has _destination => ( is => 'rw', isa => 'Str', default => sub { my $self = shift; return shift @{ $self->extra_argv }; } );
  • 42. $ perlping -v -s 512 4.2.2.2 use 5.014; has size => (is => 'rw', isa => 'Int', default => 64); has ttl => (is => 'rw', isa => 'Int', default => 50); has verbose => (is => 'rw', isa => 'Bool'); has _destination => ( is => 'rw', isa => 'Str', default => sub { my $self = shift; return shift $self->extra_argv; } );
  • 44. my suggestions Getopt::Lucid or Getopt::Long::Descriptive for one-off scripts
  • 45. my suggestions Getopt::Lucid or Getopt::Long::Descriptive for one-off scripts MooseX::Getopt or MouseX::Getopt for OO projects
  • 46. my suggestions Getopt::Lucid or Getopt::Long::Descriptive for one-off scripts MooseX::Getopt or MouseX::Getopt for OO projects App::Cmd, MooseX::App::Cmd or MouseX::App::Cmd for command-driven scripts