support scalar cmd_aliases, so that singular aliases are not so clunky to type
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute.pm
CommitLineData
5dac17c3 1
2package MooseX::Getopt::Meta::Attribute;
3use Moose;
61c9baa9 4use Moose::Util::TypeConstraints;
5dac17c3 5
8034a232 6our $VERSION = '0.01';
7our $AUTHORITY = 'cpan:STEVAN';
8
9extends 'Moose::Meta::Attribute'; # << Moose extending Moose :)
5dac17c3 10
11has '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
19subtype '_MooseX_Getopt_CmdAliases'
20 => as 'ArrayRef'
21 => where { 1 };
22coerce '_MooseX_Getopt_CmdAliases'
23 => from 'Value'
24 => via { [$_] };
25
de75868f 26has '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 33no Moose; 1;
5dac17c3 34
35__END__
36
37
38=pod
39
40=head1 NAME
41
8034a232 42MooseX::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 73This is a custom attribute metaclass which can be used to specify a
74the specific command line flag to use instead of the default one
75which L<MooseX::Getopt> will create for you.
76
77This is certainly not the prettiest way to go about this, but for
78now it works for those who might need such a feature.
79
5dac17c3 80=head1 METHODS
81
8034a232 82These methods are of little use to most users, they are used interally
83within L<MooseX::Getopt>.
84
5dac17c3 85=over 4
86
87=item B<cmd_flag>
88
de75868f 89Changes the commandline flag to be this value, instead of the default,
90which is the same as the attribute name.
91
92=item B<cmd_aliases>
93
94Adds more aliases for this commandline flag, useful for short options
95and 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
107All complex software has bugs lurking in it, and this module is no
108exception. If you find a bug please either email me, or add the bug
109to cpan-RT.
110
111=head1 AUTHOR
112
113Stevan Little E<lt>stevan@iinteractive.comE<gt>
114
115=head1 COPYRIGHT AND LICENSE
116
117Copyright 2007 by Infinity Interactive, Inc.
118
119L<http://www.iinteractive.com>
120
121This library is free software; you can redistribute it and/or modify
122it under the same terms as Perl itself.
123
de75868f 124=cut