File Coverage

blib/lib/MouseX/Getopt/Meta/Attribute/Trait.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 18 100.0


line stmt bran cond sub pod time code
1             package MouseX::Getopt::Meta::Attribute::Trait;
2             # ABSTRACT: Optional meta attribute trait for custom option names
3              
4 22     22   10326 use Mouse::Role;
  22         56  
  22         132  
5 22     22   6383 use Mouse::Util::TypeConstraints;
  22         60  
  22         160  
6              
7             has 'cmd_flag' => (
8             is => 'rw',
9             isa => 'Str',
10             predicate => 'has_cmd_flag',
11             );
12              
13             # This subtype is to support scalar -> arrayref coercion
14             # without polluting the built-in types
15             subtype '_MouseX_Getopt_CmdAliases' => as 'ArrayRef';
16              
17             coerce '_MouseX_Getopt_CmdAliases'
18             => from 'Str'
19             => via { [$_] };
20              
21             has 'cmd_aliases' => (
22             is => 'rw',
23             isa => '_MouseX_Getopt_CmdAliases',
24             predicate => 'has_cmd_aliases',
25             coerce => 1,
26             );
27              
28 22     22   4321 no Mouse::Util::TypeConstraints;
  22         53  
  22         143  
29 22     22   4006 no Mouse::Role;
  22         45  
  22         250  
30              
31             # register this as a metaclass alias ...
32             package # stop confusing PAUSE
33             Mouse::Meta::Attribute::Custom::Trait::Getopt;
34 20     20   11027 sub register_implementation { 'MouseX::Getopt::Meta::Attribute::Trait' }
35              
36             1;
37              
38             =for stopwords metaclass commandline params configfile
39              
40             =head1 SYNOPSIS
41              
42             package App;
43             use Mouse;
44              
45             with 'MouseX::Getopt';
46              
47             has 'data' => (
48             traits => [ 'Getopt' ],
49             is => 'ro',
50             isa => 'Str',
51             default => 'file.dat',
52              
53             # tells MouseX::Getopt to use --somedata as the
54             # command line flag instead of the normal
55             # autogenerated one (--data)
56             cmd_flag => 'somedata',
57              
58             # tells MouseX::Getopt to also allow --moosedata,
59             # -m, and -d as aliases for this same option on
60             # the commandline.
61             cmd_aliases => [qw/ moosedata m d /],
62              
63             # Or, you can use a plain scalar for a single alias:
64             cmd_aliases => 'm',
65             );
66              
67             =head1 DESCRIPTION
68              
69             This is a custom attribute metaclass trait which can be used to
70             specify a the specific command line flag to use instead of the
71             default one which L will create for you.
72              
73             =over 4
74              
75             =item B
76              
77             Changes the commandline flag to be this value, instead of the default,
78             which is the same as the attribute name.
79              
80             =item B
81              
82             Adds more aliases for this commandline flag, useful for short options
83             and such.
84              
85             =item B
86              
87             =item B
88              
89             =back
90              
91             =cut