Commit | Line | Data |
5dac17c3 |
1 | |
23575d46 |
2 | package MooseX::Getopt::Meta::Attribute; |
5dac17c3 |
3 | use Moose; |
61c9baa9 |
4 | use Moose::Util::TypeConstraints; |
5dac17c3 |
5 | |
f969917f |
6 | our $VERSION = '0.04'; |
8034a232 |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
9 | extends 'Moose::Meta::Attribute'; # << Moose extending Moose :) |
5dac17c3 |
10 | |
11 | has 'cmd_flag' => ( |
12 | is => 'rw', |
13 | isa => 'Str', |
14 | predicate => 'has_cmd_flag', |
15 | ); |
16 | |
61c9baa9 |
17 | # This subtype is to support scalar -> arrayref coercion |
18 | # without polluting the built-in types |
f969917f |
19 | subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef'; |
3d9a716d |
20 | |
61c9baa9 |
21 | coerce '_MooseX_Getopt_CmdAliases' |
3d9a716d |
22 | => from 'Str' |
61c9baa9 |
23 | => via { [$_] }; |
24 | |
de75868f |
25 | has 'cmd_aliases' => ( |
26 | is => 'rw', |
61c9baa9 |
27 | isa => '_MooseX_Getopt_CmdAliases', |
de75868f |
28 | predicate => 'has_cmd_aliases', |
61c9baa9 |
29 | coerce => 1, |
de75868f |
30 | ); |
31 | |
1a8b4ed1 |
32 | no Moose; |
5dac17c3 |
33 | |
1a8b4ed1 |
34 | # register this as a metaclass alias ... |
6ac028c4 |
35 | package # stop confusing PAUSE |
36 | Moose::Meta::Attribute::Custom::Getopt; |
1a8b4ed1 |
37 | sub register_implementation { 'MooseX::Getopt::Meta::Attribute' } |
38 | |
39 | 1; |
5dac17c3 |
40 | |
1a8b4ed1 |
41 | __END__ |
5dac17c3 |
42 | |
43 | =pod |
44 | |
45 | =head1 NAME |
46 | |
8034a232 |
47 | MooseX::Getopt::Meta::Attribute - Optional meta attribute for custom option names |
5dac17c3 |
48 | |
49 | =head1 SYNOPSIS |
50 | |
8034a232 |
51 | package App; |
52 | use Moose; |
53 | |
54 | with 'MooseX::Getopt'; |
55 | |
56 | has 'data' => ( |
1a8b4ed1 |
57 | metaclass => 'MooseX::Getopt::Meta::Attribute', |
8034a232 |
58 | is => 'ro', |
59 | isa => 'Str', |
60 | default => 'file.dat', |
61c9baa9 |
61 | |
de75868f |
62 | # tells MooseX::Getopt to use --somedata as the |
8034a232 |
63 | # command line flag instead of the normal |
64 | # autogenerated one (--data) |
de75868f |
65 | cmd_flag => 'somedata', |
61c9baa9 |
66 | |
de75868f |
67 | # tells MooseX::Getopt to also allow --moosedata, |
68 | # -m, and -d as aliases for this same option on |
69 | # the commandline. |
70 | cmd_aliases => [qw/ moosedata m d /], |
61c9baa9 |
71 | |
72 | # Or, you can use a plain scalar for a single alias: |
73 | cmd_aliases => 'm', |
8034a232 |
74 | ); |
75 | |
5dac17c3 |
76 | =head1 DESCRIPTION |
77 | |
8034a232 |
78 | This is a custom attribute metaclass which can be used to specify a |
79 | the specific command line flag to use instead of the default one |
80 | which L<MooseX::Getopt> will create for you. |
81 | |
82 | This is certainly not the prettiest way to go about this, but for |
83 | now it works for those who might need such a feature. |
84 | |
1a8b4ed1 |
85 | =head2 Custom Metaclass alias |
86 | |
87 | This now takes advantage of the Moose 0.19 feature to support |
88 | custom attribute metaclass aliases. This means you can also |
89 | use this as the B<Getopt> alias, like so: |
90 | |
91 | has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f'); |
92 | |
5dac17c3 |
93 | =head1 METHODS |
94 | |
8034a232 |
95 | These methods are of little use to most users, they are used interally |
96 | within L<MooseX::Getopt>. |
97 | |
5dac17c3 |
98 | =over 4 |
99 | |
100 | =item B<cmd_flag> |
101 | |
de75868f |
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 | |
5dac17c3 |
110 | =item B<has_cmd_flag> |
111 | |
de75868f |
112 | =item B<has_cmd_aliases> |
113 | |
5dac17c3 |
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 | |
3d9a716d |
128 | Brandon L. Black, E<lt>blblack@gmail.comE<gt> |
129 | |
5dac17c3 |
130 | =head1 COPYRIGHT AND LICENSE |
131 | |
132 | Copyright 2007 by Infinity Interactive, Inc. |
133 | |
134 | L<http://www.iinteractive.com> |
135 | |
136 | This library is free software; you can redistribute it and/or modify |
137 | it under the same terms as Perl itself. |
138 | |
de75868f |
139 | =cut |