use OO syntax for handling subref
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Dashes.pm
CommitLineData
5f78e881 1package MooseX::Getopt::Dashes;
669588e2 2# ABSTRACT: convert underscores in attribute names to dashes
3
5f78e881 4use Moose::Role;
5
6with 'MooseX::Getopt';
7
8around _get_cmd_flags_for_attr => sub {
9 my $next = shift;
10 my ( $class, $attr, @rest ) = @_;
11
12 my ( $flag, @aliases ) = $class->$next($attr, @rest);
13 $flag =~ tr/_/-/
14 unless $attr->does('MooseX::Getopt::Meta::Attribute::Trait')
15 && $attr->has_cmd_flag;
16
17 return ( $flag, @aliases );
18};
19
669588e2 20no Moose::Role;
5f78e881 21
669588e2 221;
5f78e881 23
5ffe2079 24=head1 SYNOPSIS
25
26 package My::App;
27 use Moose;
28 with 'MooseX::Getopt::Dashes';
29
ceeaabeb 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
5ffe2079 46 # use as MooseX::Getopt
47
5f78e881 48=head1 DESCRIPTION
49
50This is a version of C<MooseX::Getopt> which converts underscores in
51attribute names to dashes when generating command line flags.
52
ceeaabeb 53You can selectively disable this on a per-attribute basis by supplying
54a L<cmd_flag|MooseX::Getopt::Meta::Attribute/METHODS> argument with
55the command flag you'd like for a given attribute. No underscore to
56dash replacement will be done on the C<cmd_flag>.
57
5f78e881 58=cut