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