File Coverage

blib/lib/MooseX/Getopt/Dashes.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package MooseX::Getopt::Dashes;
2             # ABSTRACT: convert underscores in attribute names to dashes
3              
4             our $VERSION = '0.75';
5              
6 2     2   3259 use Moose::Role;
  2         6  
  2         17  
7             with 'MooseX::Getopt';
8 2     2   11842 use namespace::autoclean;
  2         5  
  2         16  
9              
10             around _get_cmd_flags_for_attr => sub {
11             my $next = shift;
12             my ( $class, $attr, @rest ) = @_;
13              
14             my ( $flag, @aliases ) = $class->$next($attr, @rest);
15             $flag =~ tr/_/-/
16             unless $attr->does('MooseX::Getopt::Meta::Attribute::Trait')
17             && $attr->has_cmd_flag;
18              
19             return ( $flag, @aliases );
20             };
21              
22             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             MooseX::Getopt::Dashes - convert underscores in attribute names to dashes
33              
34             =head1 VERSION
35              
36             version 0.75
37              
38             =head1 SYNOPSIS
39              
40             package My::App;
41             use Moose;
42             with 'MooseX::Getopt::Dashes';
43              
44             # Will be called as --some-thingy, not --some_thingy
45             has 'some_thingy' => (
46             is => 'ro',
47             isa => 'Str',
48             default => 'foo'
49             );
50              
51             # Will be called as --another_thingy, not --another-thingy
52             has 'another_thingy' => (
53             traits => [ 'Getopt' ],
54             cmd_flag => 'another_thingy'
55             is => 'ro',
56             isa => 'Str',
57             default => 'foo'
58             );
59              
60             # use as MooseX::Getopt
61              
62             =head1 DESCRIPTION
63              
64             This is a version of L<MooseX::Getopt> which converts underscores in
65             attribute names to dashes when generating command line flags.
66              
67             You can selectively disable this on a per-attribute basis by supplying
68             a L<cmd_flag|MooseX::Getopt::Meta::Attribute/METHODS> argument with
69             the command flag you'd like for a given attribute. No underscore to
70             dash replacement will be done on the C<cmd_flag>.
71              
72             =head1 SUPPORT
73              
74             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Getopt>
75             (or L<bug-MooseX-Getopt@rt.cpan.org|mailto:bug-MooseX-Getopt@rt.cpan.org>).
76              
77             There is also a mailing list available for users of this distribution, at
78             L<http://lists.perl.org/list/moose.html>.
79              
80             There is also an irc channel available for users of this distribution, at
81             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
82              
83             =head1 AUTHOR
84              
85             Stevan Little <stevan@iinteractive.com>
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             This software is copyright (c) 2007 by Infinity Interactive, Inc.
90              
91             This is free software; you can redistribute it and/or modify it under
92             the same terms as the Perl 5 programming language system itself.
93              
94             =cut