Version 0.27.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute / Trait.pm
CommitLineData
adbe3e57 1
2package MooseX::Getopt::Meta::Attribute::Trait;
3use Moose::Role;
4use Moose::Util::TypeConstraints;
5
04dc0852 6our $VERSION = '0.27';
adbe3e57 7our $AUTHORITY = 'cpan:STEVAN';
8
9has 'cmd_flag' => (
10 is => 'rw',
11 isa => 'Str',
12 predicate => 'has_cmd_flag',
13);
14
15# This subtype is to support scalar -> arrayref coercion
16# without polluting the built-in types
17subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef';
18
19coerce '_MooseX_Getopt_CmdAliases'
20 => from 'Str'
21 => via { [$_] };
22
23has 'cmd_aliases' => (
24 is => 'rw',
25 isa => '_MooseX_Getopt_CmdAliases',
26 predicate => 'has_cmd_aliases',
27 coerce => 1,
28);
29
30no Moose::Role;
31
32# register this as a metaclass alias ...
33package # stop confusing PAUSE
34 Moose::Meta::Attribute::Custom::Trait::Getopt;
35sub register_implementation { 'MooseX::Getopt::Meta::Attribute::Trait' }
36
371;
38
39__END__
40
41=pod
42
43=head1 NAME
44
45MooseX::Getopt::Meta::Attribute::Trait - Optional meta attribute trait for custom option names
46
47=head1 SYNOPSIS
48
49 package App;
50 use Moose;
51
52 with 'MooseX::Getopt';
53
54 has 'data' => (
55 traits => [ 'Getopt' ],
56 is => 'ro',
57 isa => 'Str',
58 default => 'file.dat',
59
60 # tells MooseX::Getopt to use --somedata as the
61 # command line flag instead of the normal
62 # autogenerated one (--data)
63 cmd_flag => 'somedata',
64
65 # tells MooseX::Getopt to also allow --moosedata,
66 # -m, and -d as aliases for this same option on
67 # the commandline.
68 cmd_aliases => [qw/ moosedata m d /],
69
70 # Or, you can use a plain scalar for a single alias:
71 cmd_aliases => 'm',
72 );
73
74=head1 DESCRIPTION
75
76This is a custom attribute metaclass trait which can be used to
77specify a the specific command line flag to use instead of the
78default one which L<MooseX::Getopt> will create for you.
79
80=head1 METHODS
81
82These methods are of little use to most users, they are used interally
83within L<MooseX::Getopt>.
84
85=over 4
86
87=item B<cmd_flag>
88
89Changes the commandline flag to be this value, instead of the default,
90which is the same as the attribute name.
91
92=item B<cmd_aliases>
93
94Adds more aliases for this commandline flag, useful for short options
95and such.
96
97=item B<has_cmd_flag>
98
99=item B<has_cmd_aliases>
100
101=item B<meta>
102
103=back
104
105=head1 BUGS
106
107All complex software has bugs lurking in it, and this module is no
108exception. If you find a bug please either email me, or add the bug
109to cpan-RT.
110
111=head1 AUTHOR
112
113Stevan Little E<lt>stevan@iinteractive.comE<gt>
114
115=head1 COPYRIGHT AND LICENSE
116
117Copyright 2007-2008 by Infinity Interactive, Inc.
118
119L<http://www.iinteractive.com>
120
121This library is free software; you can redistribute it and/or modify
122it under the same terms as Perl itself.
123
124=cut