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