Commit | Line | Data |
adbe3e57 |
1 | |
2 | package MooseX::Getopt::Meta::Attribute::Trait; |
3 | use Moose::Role; |
4 | use Moose::Util::TypeConstraints; |
5 | |
a2664368 |
6 | our $VERSION = '0.20'; |
adbe3e57 |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
9 | has 'cmd_flag' => ( |
10 | is => 'rw', |
11 | isa => 'Str', |
12 | predicate => 'has_cmd_flag', |
13 | ); |
14 | |
15 | # This subtype is to support scalar -> arrayref coercion |
16 | # without polluting the built-in types |
17 | subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef'; |
18 | |
19 | coerce '_MooseX_Getopt_CmdAliases' |
20 | => from 'Str' |
21 | => via { [$_] }; |
22 | |
23 | has 'cmd_aliases' => ( |
24 | is => 'rw', |
25 | isa => '_MooseX_Getopt_CmdAliases', |
26 | predicate => 'has_cmd_aliases', |
27 | coerce => 1, |
28 | ); |
29 | |
30 | no Moose::Role; |
31 | |
32 | # register this as a metaclass alias ... |
33 | package # stop confusing PAUSE |
34 | Moose::Meta::Attribute::Custom::Trait::Getopt; |
35 | sub register_implementation { 'MooseX::Getopt::Meta::Attribute::Trait' } |
36 | |
37 | 1; |
38 | |
39 | __END__ |
40 | |
41 | =pod |
42 | |
43 | =head1 NAME |
44 | |
45 | MooseX::Getopt::Meta::Attribute::Trait - Optional meta attribute trait for custom option names |
46 | |
47 | =head1 SYNOPSIS |
48 | |
49 | package App; |
50 | use Moose; |
51 | |
52 | with 'MooseX::Getopt'; |
53 | |
54 | has 'data' => ( |
55 | traits => [ 'Getopt' ], |
56 | is => 'ro', |
57 | isa => 'Str', |
58 | default => 'file.dat', |
59 | |
60 | # tells MooseX::Getopt to use --somedata as the |
61 | # command line flag instead of the normal |
62 | # autogenerated one (--data) |
63 | cmd_flag => 'somedata', |
64 | |
65 | # tells MooseX::Getopt to also allow --moosedata, |
66 | # -m, and -d as aliases for this same option on |
67 | # the commandline. |
68 | cmd_aliases => [qw/ moosedata m d /], |
69 | |
70 | # Or, you can use a plain scalar for a single alias: |
71 | cmd_aliases => 'm', |
72 | ); |
73 | |
74 | =head1 DESCRIPTION |
75 | |
76 | This is a custom attribute metaclass trait which can be used to |
77 | specify a the specific command line flag to use instead of the |
78 | default one which L<MooseX::Getopt> will create for you. |
79 | |
80 | =head1 METHODS |
81 | |
82 | These methods are of little use to most users, they are used interally |
83 | within L<MooseX::Getopt>. |
84 | |
85 | =over 4 |
86 | |
87 | =item B<cmd_flag> |
88 | |
89 | Changes the commandline flag to be this value, instead of the default, |
90 | which is the same as the attribute name. |
91 | |
92 | =item B<cmd_aliases> |
93 | |
94 | Adds more aliases for this commandline flag, useful for short options |
95 | and such. |
96 | |
97 | =item B<has_cmd_flag> |
98 | |
99 | =item B<has_cmd_aliases> |
100 | |
101 | =item B<meta> |
102 | |
103 | =back |
104 | |
105 | =head1 BUGS |
106 | |
107 | All complex software has bugs lurking in it, and this module is no |
108 | exception. If you find a bug please either email me, or add the bug |
109 | to cpan-RT. |
110 | |
111 | =head1 AUTHOR |
112 | |
113 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
114 | |
115 | =head1 COPYRIGHT AND LICENSE |
116 | |
117 | Copyright 2007-2008 by Infinity Interactive, Inc. |
118 | |
119 | L<http://www.iinteractive.com> |
120 | |
121 | This library is free software; you can redistribute it and/or modify |
122 | it under the same terms as Perl itself. |
123 | |
124 | =cut |