Commit | Line | Data |
5dac17c3 |
1 | |
3d9a716d |
2 | package ; |
5dac17c3 |
3 | use Moose; |
61c9baa9 |
4 | use Moose::Util::TypeConstraints; |
5dac17c3 |
5 | |
1a8b4ed1 |
6 | our $VERSION = '0.02'; |
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 |
19 | subtype '_MooseX_Getopt_CmdAliases' |
20 | => as 'ArrayRef' |
3d9a716d |
21 | => where { 1 }; |
22 | |
61c9baa9 |
23 | coerce '_MooseX_Getopt_CmdAliases' |
3d9a716d |
24 | => from 'Str' |
61c9baa9 |
25 | => via { [$_] }; |
26 | |
de75868f |
27 | has 'cmd_aliases' => ( |
28 | is => 'rw', |
61c9baa9 |
29 | isa => '_MooseX_Getopt_CmdAliases', |
de75868f |
30 | predicate => 'has_cmd_aliases', |
61c9baa9 |
31 | coerce => 1, |
de75868f |
32 | ); |
33 | |
1a8b4ed1 |
34 | no Moose; |
5dac17c3 |
35 | |
1a8b4ed1 |
36 | # register this as a metaclass alias ... |
37 | package Moose::Meta::Attribute::Custom::Getopt; |
38 | sub register_implementation { 'MooseX::Getopt::Meta::Attribute' } |
39 | |
40 | 1; |
5dac17c3 |
41 | |
1a8b4ed1 |
42 | __END__ |
5dac17c3 |
43 | |
44 | =pod |
45 | |
46 | =head1 NAME |
47 | |
8034a232 |
48 | MooseX::Getopt::Meta::Attribute - Optional meta attribute for custom option names |
5dac17c3 |
49 | |
50 | =head1 SYNOPSIS |
51 | |
8034a232 |
52 | package App; |
53 | use Moose; |
54 | |
55 | with 'MooseX::Getopt'; |
56 | |
57 | has 'data' => ( |
1a8b4ed1 |
58 | metaclass => 'MooseX::Getopt::Meta::Attribute', |
8034a232 |
59 | is => 'ro', |
60 | isa => 'Str', |
61 | default => 'file.dat', |
61c9baa9 |
62 | |
de75868f |
63 | # tells MooseX::Getopt to use --somedata as the |
8034a232 |
64 | # command line flag instead of the normal |
65 | # autogenerated one (--data) |
de75868f |
66 | cmd_flag => 'somedata', |
61c9baa9 |
67 | |
de75868f |
68 | # tells MooseX::Getopt to also allow --moosedata, |
69 | # -m, and -d as aliases for this same option on |
70 | # the commandline. |
71 | cmd_aliases => [qw/ moosedata m d /], |
61c9baa9 |
72 | |
73 | # Or, you can use a plain scalar for a single alias: |
74 | cmd_aliases => 'm', |
8034a232 |
75 | ); |
76 | |
5dac17c3 |
77 | =head1 DESCRIPTION |
78 | |
8034a232 |
79 | This is a custom attribute metaclass which can be used to specify a |
80 | the specific command line flag to use instead of the default one |
81 | which L<MooseX::Getopt> will create for you. |
82 | |
83 | This is certainly not the prettiest way to go about this, but for |
84 | now it works for those who might need such a feature. |
85 | |
1a8b4ed1 |
86 | =head2 Custom Metaclass alias |
87 | |
88 | This now takes advantage of the Moose 0.19 feature to support |
89 | custom attribute metaclass aliases. This means you can also |
90 | use this as the B<Getopt> alias, like so: |
91 | |
92 | has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f'); |
93 | |
5dac17c3 |
94 | =head1 METHODS |
95 | |
8034a232 |
96 | These methods are of little use to most users, they are used interally |
97 | within L<MooseX::Getopt>. |
98 | |
5dac17c3 |
99 | =over 4 |
100 | |
101 | =item B<cmd_flag> |
102 | |
de75868f |
103 | Changes the commandline flag to be this value, instead of the default, |
104 | which is the same as the attribute name. |
105 | |
106 | =item B<cmd_aliases> |
107 | |
108 | Adds more aliases for this commandline flag, useful for short options |
109 | and such. |
110 | |
5dac17c3 |
111 | =item B<has_cmd_flag> |
112 | |
de75868f |
113 | =item B<has_cmd_aliases> |
114 | |
5dac17c3 |
115 | =item B<meta> |
116 | |
117 | =back |
118 | |
119 | =head1 BUGS |
120 | |
121 | All complex software has bugs lurking in it, and this module is no |
122 | exception. If you find a bug please either email me, or add the bug |
123 | to cpan-RT. |
124 | |
125 | =head1 AUTHOR |
126 | |
127 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
128 | |
3d9a716d |
129 | Brandon L. Black, E<lt>blblack@gmail.comE<gt> |
130 | |
5dac17c3 |
131 | =head1 COPYRIGHT AND LICENSE |
132 | |
133 | Copyright 2007 by Infinity Interactive, Inc. |
134 | |
135 | L<http://www.iinteractive.com> |
136 | |
137 | This library is free software; you can redistribute it and/or modify |
138 | it under the same terms as Perl itself. |
139 | |
de75868f |
140 | =cut |