Commit | Line | Data |
5dac17c3 |
1 | |
2 | package MooseX::Getopt::Meta::Attribute; |
3 | use Moose; |
61c9baa9 |
4 | use Moose::Util::TypeConstraints; |
5dac17c3 |
5 | |
8034a232 |
6 | our $VERSION = '0.01'; |
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' |
21 | => where { 1 }; |
22 | coerce '_MooseX_Getopt_CmdAliases' |
23 | => from 'Value' |
24 | => via { [$_] }; |
25 | |
de75868f |
26 | has 'cmd_aliases' => ( |
27 | is => 'rw', |
61c9baa9 |
28 | isa => '_MooseX_Getopt_CmdAliases', |
de75868f |
29 | predicate => 'has_cmd_aliases', |
61c9baa9 |
30 | coerce => 1, |
de75868f |
31 | ); |
32 | |
8034a232 |
33 | no Moose; 1; |
5dac17c3 |
34 | |
35 | __END__ |
36 | |
37 | |
38 | =pod |
39 | |
40 | =head1 NAME |
41 | |
8034a232 |
42 | MooseX::Getopt::Meta::Attribute - Optional meta attribute for custom option names |
5dac17c3 |
43 | |
44 | =head1 SYNOPSIS |
45 | |
8034a232 |
46 | package App; |
47 | use Moose; |
48 | |
49 | with 'MooseX::Getopt'; |
50 | |
51 | has 'data' => ( |
52 | metaclass => 'MooseX::Getopt::Meta::Attribute', |
53 | is => 'ro', |
54 | isa => 'Str', |
55 | default => 'file.dat', |
61c9baa9 |
56 | |
de75868f |
57 | # tells MooseX::Getopt to use --somedata as the |
8034a232 |
58 | # command line flag instead of the normal |
59 | # autogenerated one (--data) |
de75868f |
60 | cmd_flag => 'somedata', |
61c9baa9 |
61 | |
de75868f |
62 | # tells MooseX::Getopt to also allow --moosedata, |
63 | # -m, and -d as aliases for this same option on |
64 | # the commandline. |
65 | cmd_aliases => [qw/ moosedata m d /], |
61c9baa9 |
66 | |
67 | # Or, you can use a plain scalar for a single alias: |
68 | cmd_aliases => 'm', |
8034a232 |
69 | ); |
70 | |
5dac17c3 |
71 | =head1 DESCRIPTION |
72 | |
8034a232 |
73 | This is a custom attribute metaclass which can be used to specify a |
74 | the specific command line flag to use instead of the default one |
75 | which L<MooseX::Getopt> will create for you. |
76 | |
77 | This is certainly not the prettiest way to go about this, but for |
78 | now it works for those who might need such a feature. |
79 | |
5dac17c3 |
80 | =head1 METHODS |
81 | |
8034a232 |
82 | These methods are of little use to most users, they are used interally |
83 | within L<MooseX::Getopt>. |
84 | |
5dac17c3 |
85 | =over 4 |
86 | |
87 | =item B<cmd_flag> |
88 | |
de75868f |
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 | |
5dac17c3 |
97 | =item B<has_cmd_flag> |
98 | |
de75868f |
99 | =item B<has_cmd_aliases> |
100 | |
5dac17c3 |
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 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 | |
de75868f |
124 | =cut |