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