From: Ævar Arnfjörð Bjarmason Date: Fri, 12 Feb 2010 18:22:13 +0000 (+0000) Subject: MooseX::Getopt::Dashes: Document how ::Dashes interacts with the cmd_flag argument X-Git-Tag: 0.27~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ceeaabeb2c434c734638bab55c728647c34d2c9a;p=gitmo%2FMooseX-Getopt.git MooseX::Getopt::Dashes: Document how ::Dashes interacts with the cmd_flag argument Document that using a cmd_flag argument to attributes can be used to override the tr/_/-/ replacement ::Dashes does on attribute names --- diff --git a/ChangeLog b/ChangeLog index 7f63092..4a8f154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ Revision history for Perl extension MooseX-Getopt + * MooseX::Getopt::Dashes + - Document that using a cmd_flag argument to attributes can be used to + override the tr/_/-/ replacement ::Dashes does on attribute names + 0.26 Thu. Dec 10 2009 * MooseX::Getopt::Basic - Fix bug with attribute names containing upper case letters. diff --git a/lib/MooseX/Getopt/Dashes.pm b/lib/MooseX/Getopt/Dashes.pm index ed42761..bb8a9bb 100644 --- a/lib/MooseX/Getopt/Dashes.pm +++ b/lib/MooseX/Getopt/Dashes.pm @@ -31,6 +31,22 @@ MooseX::Getopt::Dashes - convert underscores in attribute names to dashes use Moose; with 'MooseX::Getopt::Dashes'; + # Will be called as --some-thingy, not --some_thingy + has 'some_thingy' => ( + is => 'ro', + isa => 'Str', + default => 'foo' + ); + + # Will be called as --another_thingy, not --another-thingy + has 'another_thingy' => ( + traits => [ 'Getopt' ], + cmd_flag => 'another_thingy' + is => 'ro', + isa => 'Str', + default => 'foo' + ); + # use as MooseX::Getopt =head1 DESCRIPTION @@ -38,6 +54,11 @@ MooseX::Getopt::Dashes - convert underscores in attribute names to dashes This is a version of C which converts underscores in attribute names to dashes when generating command line flags. +You can selectively disable this on a per-attribute basis by supplying +a L argument with +the command flag you'd like for a given attribute. No underscore to +dash replacement will be done on the C. + =head1 METHODS =over 4 @@ -60,6 +81,8 @@ Stevan Little Estevan@iinteractive.comE Yuval Kogman C<< >> +Evar ArnfjErE Bjarmason Eavar@cpan.orgE + =head1 COPYRIGHT AND LICENSE Copyright 2007-2008 by Infinity Interactive, Inc. diff --git a/t/010_dashes.t b/t/010_dashes.t index 4ec1248..2927dae 100644 --- a/t/010_dashes.t +++ b/t/010_dashes.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 5; use Test::Exception; @@ -19,14 +19,25 @@ BEGIN { with 'MooseX::Getopt::Dashes'; has 'some_thingy' => ( is => 'ro', isa => 'Str', default => 'foo' ); + has 'another_thingy' => ( is => 'ro', isa => 'Str', default => 'foo', cmd_flag => 'another_thingy', traits => [ 'Getopt' ], ); } { local @ARGV = (qw/--some-thingy bar/); - lives_and { is( App->new_with_options->some_thingy, 'bar') } 'Dash in option name'; + lives_and { is( App->new_with_options->some_thingy, 'bar') } 'Dash in option name'; } { - local @ARGV = (qw/--some_thingy bar/); - throws_ok { App->new_with_options } qr/Unknown option: some_thingy/; + local @ARGV = (qw/--some_thingy bar/); + throws_ok { App->new_with_options } qr/Unknown option: some_thingy/; +} + +{ + local @ARGV = (qw/--another_thingy bar/); + lives_and { is( App->new_with_options->another_thingy, 'bar' ) } 'Underscore in option name'; +} + +{ + local @ARGV = (qw/--another-thingy bar/); + throws_ok { App->new_with_options } qr/Unknown option: another-thingy/; }