some doc fixes
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute.pm
CommitLineData
5dac17c3 1
23575d46 2package MooseX::Getopt::Meta::Attribute;
5dac17c3 3use Moose;
61c9baa9 4use Moose::Util::TypeConstraints;
5dac17c3 5
f969917f 6our $VERSION = '0.04';
8034a232 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
f969917f 19subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef';
3d9a716d 20
61c9baa9 21coerce '_MooseX_Getopt_CmdAliases'
3d9a716d 22 => from 'Str'
61c9baa9 23 => via { [$_] };
24
de75868f 25has '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 32no Moose;
5dac17c3 33
1a8b4ed1 34# register this as a metaclass alias ...
6ac028c4 35package # stop confusing PAUSE
36 Moose::Meta::Attribute::Custom::Getopt;
1a8b4ed1 37sub register_implementation { 'MooseX::Getopt::Meta::Attribute' }
38
391;
5dac17c3 40
1a8b4ed1 41__END__
5dac17c3 42
43=pod
44
45=head1 NAME
46
8034a232 47MooseX::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 78This is a custom attribute metaclass which can be used to specify a
79the specific command line flag to use instead of the default one
80which L<MooseX::Getopt> will create for you.
81
82This is certainly not the prettiest way to go about this, but for
83now it works for those who might need such a feature.
84
1a8b4ed1 85=head2 Custom Metaclass alias
86
87This now takes advantage of the Moose 0.19 feature to support
88custom attribute metaclass aliases. This means you can also
89use this as the B<Getopt> alias, like so:
90
91 has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');
92
5dac17c3 93=head1 METHODS
94
8034a232 95These methods are of little use to most users, they are used interally
96within L<MooseX::Getopt>.
97
5dac17c3 98=over 4
99
100=item B<cmd_flag>
101
de75868f 102Changes the commandline flag to be this value, instead of the default,
103which is the same as the attribute name.
104
105=item B<cmd_aliases>
106
107Adds more aliases for this commandline flag, useful for short options
108and 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
120All complex software has bugs lurking in it, and this module is no
121exception. If you find a bug please either email me, or add the bug
122to cpan-RT.
123
124=head1 AUTHOR
125
126Stevan Little E<lt>stevan@iinteractive.comE<gt>
127
3d9a716d 128Brandon L. Black, E<lt>blblack@gmail.comE<gt>
129
5dac17c3 130=head1 COPYRIGHT AND LICENSE
131
132Copyright 2007 by Infinity Interactive, Inc.
133
134L<http://www.iinteractive.com>
135
136This library is free software; you can redistribute it and/or modify
137it under the same terms as Perl itself.
138
de75868f 139=cut