MooseX::Getopt::Dashes: Document how ::Dashes interacts with the cmd_flag argument
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Dashes.pm
CommitLineData
5f78e881 1package MooseX::Getopt::Dashes;
2use Moose::Role;
3
4with 'MooseX::Getopt';
5
6around _get_cmd_flags_for_attr => sub {
7 my $next = shift;
8 my ( $class, $attr, @rest ) = @_;
9
10 my ( $flag, @aliases ) = $class->$next($attr, @rest);
11 $flag =~ tr/_/-/
12 unless $attr->does('MooseX::Getopt::Meta::Attribute::Trait')
13 && $attr->has_cmd_flag;
14
15 return ( $flag, @aliases );
16};
17
181;
19
20__END__
21
22=pod
23
24=head1 NAME
25
26MooseX::Getopt::Dashes - convert underscores in attribute names to dashes
27
5ffe2079 28=head1 SYNOPSIS
29
30 package My::App;
31 use Moose;
32 with 'MooseX::Getopt::Dashes';
33
ceeaabeb 34 # Will be called as --some-thingy, not --some_thingy
35 has 'some_thingy' => (
36 is => 'ro',
37 isa => 'Str',
38 default => 'foo'
39 );
40
41 # Will be called as --another_thingy, not --another-thingy
42 has 'another_thingy' => (
43 traits => [ 'Getopt' ],
44 cmd_flag => 'another_thingy'
45 is => 'ro',
46 isa => 'Str',
47 default => 'foo'
48 );
49
5ffe2079 50 # use as MooseX::Getopt
51
5f78e881 52=head1 DESCRIPTION
53
54This is a version of C<MooseX::Getopt> which converts underscores in
55attribute names to dashes when generating command line flags.
56
ceeaabeb 57You can selectively disable this on a per-attribute basis by supplying
58a L<cmd_flag|MooseX::Getopt::Meta::Attribute/METHODS> argument with
59the command flag you'd like for a given attribute. No underscore to
60dash replacement will be done on the C<cmd_flag>.
61
5f78e881 62=head1 METHODS
63
64=over 4
65
66=item meta
67
68=back
69
70=head1 BUGS
71
72All complex software has bugs lurking in it, and this module is no
73exception. If you find a bug please either email me, or add the bug
74to cpan-RT.
75
76=head1 AUTHOR
77
78Dagfinn Ilmari MannsE<aring>ker E<lt>ilmari@ilmari.orgE<gt>
79
80Stevan Little E<lt>stevan@iinteractive.comE<gt>
81
82Yuval Kogman C<< <nuffin@cpan.org> >>
83
ceeaabeb 84E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason E<lt>avar@cpan.orgE<gt>
85
5f78e881 86=head1 COPYRIGHT AND LICENSE
87
88Copyright 2007-2008 by Infinity Interactive, Inc.
89
90L<http://www.iinteractive.com>
91
92This library is free software; you can redistribute it and/or modify
93it under the same terms as Perl itself.
94
95=cut