spelling (RT#87780)
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute.pm
CommitLineData
23575d46 1package MooseX::Getopt::Meta::Attribute;
669588e2 2# ABSTRACT: Optional meta attribute for custom option names
3
5dac17c3 4use Moose;
61c9baa9 5use Moose::Util::TypeConstraints;
5dac17c3 6
8034a232 7extends 'Moose::Meta::Attribute'; # << Moose extending Moose :)
adbe3e57 8 with 'MooseX::Getopt::Meta::Attribute::Trait';
de75868f 9
1a8b4ed1 10no Moose;
5dac17c3 11
1a8b4ed1 12# register this as a metaclass alias ...
669588e2 13package # stop confusing PAUSE
6ac028c4 14 Moose::Meta::Attribute::Custom::Getopt;
1a8b4ed1 15sub register_implementation { 'MooseX::Getopt::Meta::Attribute' }
16
171;
5dac17c3 18
5dac17c3 19=head1 SYNOPSIS
20
8034a232 21 package App;
22 use Moose;
669588e2 23
8034a232 24 with 'MooseX::Getopt';
669588e2 25
8034a232 26 has 'data' => (
75c37b0c 27 metaclass => 'Getopt',
8034a232 28 is => 'ro',
29 isa => 'Str',
30 default => 'file.dat',
61c9baa9 31
669588e2 32 # tells MooseX::Getopt to use --somedata as the
33 # command line flag instead of the normal
8034a232 34 # autogenerated one (--data)
de75868f 35 cmd_flag => 'somedata',
61c9baa9 36
de75868f 37 # tells MooseX::Getopt to also allow --moosedata,
38 # -m, and -d as aliases for this same option on
39 # the commandline.
40 cmd_aliases => [qw/ moosedata m d /],
61c9baa9 41
42 # Or, you can use a plain scalar for a single alias:
43 cmd_aliases => 'm',
8034a232 44 );
45
5dac17c3 46=head1 DESCRIPTION
47
669588e2 48This is a custom attribute metaclass which can be used to specify a
49the specific command line flag to use instead of the default one
50which L<MooseX::Getopt> will create for you.
8034a232 51
669588e2 52This is certainly not the prettiest way to go about this, but for
8034a232 53now it works for those who might need such a feature.
54
195fb408 55=head2 Use 'traits' instead of 'metaclass'
56
57You should rarely need to explicitly set the attribute metaclass. It is much
58preferred to simply provide a trait (a role applied to the attribute
74771704 59metaclass), which allows other code to further modify the attribute by applying
195fb408 60additional roles.
61
62Therefore, you should first try to do this:
63
64 has 'foo' => (traits => ['Getopt'], cmd_flag => 'f');
65
1a8b4ed1 66=head2 Custom Metaclass alias
67
669588e2 68This now takes advantage of the Moose 0.19 feature to support
1a8b4ed1 69custom attribute metaclass aliases. This means you can also
70use this as the B<Getopt> alias, like so:
71
72 has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');
73
669588e2 74=method B<cmd_flag>
5dac17c3 75
de75868f 76Changes the commandline flag to be this value, instead of the default,
77which is the same as the attribute name.
78
669588e2 79=method B<cmd_aliases>
de75868f 80
81Adds more aliases for this commandline flag, useful for short options
82and such.
83
669588e2 84=method B<has_cmd_flag>
5dac17c3 85
669588e2 86=method B<has_cmd_aliases>
5dac17c3 87
de75868f 88=cut