SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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 入門
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

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