bb8a9bb2f9a90fc31c86fdab1ab5d3c28293e89f
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Dashes.pm
1 package MooseX::Getopt::Dashes;
2 use Moose::Role;
3
4 with 'MooseX::Getopt';
5
6 around _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
18 1;
19
20 __END__
21
22 =pod
23
24 =head1 NAME
25
26 MooseX::Getopt::Dashes - convert underscores in attribute names to dashes
27
28 =head1 SYNOPSIS
29
30   package My::App;
31   use Moose;
32   with 'MooseX::Getopt::Dashes';
33
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
50   # use as MooseX::Getopt
51
52 =head1 DESCRIPTION
53
54 This is a version of C<MooseX::Getopt> which converts underscores in
55 attribute names to dashes when generating command line flags.
56
57 You can selectively disable this on a per-attribute basis by supplying
58 a L<cmd_flag|MooseX::Getopt::Meta::Attribute/METHODS> argument with
59 the command flag you'd like for a given attribute. No underscore to
60 dash replacement will be done on the C<cmd_flag>.
61
62 =head1 METHODS
63
64 =over 4
65
66 =item meta
67
68 =back
69
70 =head1 BUGS
71
72 All complex software has bugs lurking in it, and this module is no
73 exception. If you find a bug please either email me, or add the bug
74 to cpan-RT.
75
76 =head1 AUTHOR
77
78 Dagfinn Ilmari MannsE<aring>ker E<lt>ilmari@ilmari.orgE<gt>
79
80 Stevan Little E<lt>stevan@iinteractive.comE<gt>
81
82 Yuval Kogman  C<< <nuffin@cpan.org> >>
83
84 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason E<lt>avar@cpan.orgE<gt>
85
86 =head1 COPYRIGHT AND LICENSE
87
88 Copyright 2007-2008 by Infinity Interactive, Inc.
89
90 L<http://www.iinteractive.com>
91
92 This library is free software; you can redistribute it and/or modify
93 it under the same terms as Perl itself.
94
95 =cut