fd89a3f10a6fd3a7c9b9cd3b9165deffc44eba01
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute.pm
1 package MooseX::Getopt::Meta::Attribute;
2 # ABSTRACT: Optional meta attribute for custom option names
3
4 use Moose;
5 use Moose::Util::TypeConstraints;
6
7 extends 'Moose::Meta::Attribute'; # << Moose extending Moose :)
8    with 'MooseX::Getopt::Meta::Attribute::Trait';
9
10 no Moose;
11
12 # register this as a metaclass alias ...
13 package # stop confusing PAUSE
14     Moose::Meta::Attribute::Custom::Getopt;
15 sub register_implementation { 'MooseX::Getopt::Meta::Attribute' }
16
17 1;
18
19 =head1 SYNOPSIS
20
21   package App;
22   use Moose;
23
24   with 'MooseX::Getopt';
25
26   has 'data' => (
27       metaclass => ['Getopt'],
28       is        => 'ro',
29       isa       => 'Str',
30       default   => 'file.dat',
31
32       # tells MooseX::Getopt to use --somedata as the
33       # command line flag instead of the normal
34       # autogenerated one (--data)
35       cmd_flag  => 'somedata',
36
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 /],
41
42       # Or, you can use a plain scalar for a single alias:
43       cmd_aliases => 'm',
44   );
45
46 =head1 DESCRIPTION
47
48 This is a custom attribute metaclass which can be used to specify a
49 the specific command line flag to use instead of the default one
50 which L<MooseX::Getopt> will create for you.
51
52 This is certainly not the prettiest way to go about this, but for
53 now it works for those who might need such a feature.
54
55 =head2 Custom Metaclass alias
56
57 This now takes advantage of the Moose 0.19 feature to support
58 custom attribute metaclass aliases. This means you can also
59 use this as the B<Getopt> alias, like so:
60
61   has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');
62
63 =method B<cmd_flag>
64
65 Changes the commandline flag to be this value, instead of the default,
66 which is the same as the attribute name.
67
68 =method B<cmd_aliases>
69
70 Adds more aliases for this commandline flag, useful for short options
71 and such.
72
73 =method B<has_cmd_flag>
74
75 =method B<has_cmd_aliases>
76
77 =cut