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