| 1 | package MouseX::Getopt::Dashes; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: convert underscores in attribute names to dashes | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mouse::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | with 'MouseX::Getopt'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | around _get_cmd_flags_for_attr => sub { | ||||||||||||||||||||||||||||
| 9 | 12 | ▶ | my $next = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 10 | 12 | my ( $class, $attr, @rest ) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 12 | my ( $flag, @aliases ) = $class->$next($attr, @rest); | |||||||||||||||||||||||||||
| 13 | 12 | ▶ | $flag =~ tr/_/-/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->does("MouseX::Getopt::Meta::Attribute::Trait") and $attr->has_cmd_flag
MC/DC50%1/2
$attr->does("MouseX::Getopt::Meta::Attribute::Trait") and $attr->has_cmd_flag
$attr->does("MouseX::Getopt::Meta::Attribute::Trait")
$attr->has_cmd_flag
Truth table66%2/3
A and B
A= $attr->does("MouseX::Getopt::Meta::Attribute::Trait")B= $attr->has_cmd_flag
| |||||||||||||||||||||||||||||
| 14 | unless $attr->does('MouseX::Getopt::Meta::Attribute::Trait') | ||||||||||||||||||||||||||||
| 15 | && $attr->has_cmd_flag; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | return ( $flag, @aliases ); | |||||||||||||||||||||||||||
| 18 | 1 | }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | no Mouse::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | 1; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | package My::App; | ||||||||||||||||||||||||||||
| 27 | use Mouse; | ||||||||||||||||||||||||||||
| 28 | with 'MouseX::Getopt::Dashes'; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Will be called as --some-thingy, not --some_thingy | ||||||||||||||||||||||||||||
| 31 | has 'some_thingy' => ( | ||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | isa => 'Str', | ||||||||||||||||||||||||||||
| 34 | default => 'foo' | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Will be called as --another_thingy, not --another-thingy | ||||||||||||||||||||||||||||
| 38 | has 'another_thingy' => ( | ||||||||||||||||||||||||||||
| 39 | traits => [ 'Getopt' ], | ||||||||||||||||||||||||||||
| 40 | cmd_flag => 'another_thingy' | ||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||
| 42 | isa => 'Str', | ||||||||||||||||||||||||||||
| 43 | default => 'foo' | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # use as MouseX::Getopt | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | This is a version of C<MouseX::Getopt> which converts underscores in | ||||||||||||||||||||||||||||
| 51 | attribute names to dashes when generating command line flags. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | You can selectively disable this on a per-attribute basis by supplying | ||||||||||||||||||||||||||||
| 54 | a L<cmd_flag|MouseX::Getopt::Meta::Attribute/METHODS> argument with | ||||||||||||||||||||||||||||
| 55 | the command flag you'd like for a given attribute. No underscore to | ||||||||||||||||||||||||||||
| 56 | dash replacement will be done on the C<cmd_flag>. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||