2 package MooseX::Getopt::Meta::Attribute;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'Moose::Meta::Attribute'; # << Moose extending Moose :)
14 predicate => 'has_cmd_flag',
17 # This subtype is to support scalar -> arrayref coercion
18 # without polluting the built-in types
19 subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef';
21 coerce '_MooseX_Getopt_CmdAliases'
25 has 'cmd_aliases' => (
27 isa => '_MooseX_Getopt_CmdAliases',
28 predicate => 'has_cmd_aliases',
34 # register this as a metaclass alias ...
35 package # stop confusing PAUSE
36 Moose::Meta::Attribute::Custom::Getopt;
37 sub register_implementation { 'MooseX::Getopt::Meta::Attribute' }
47 MooseX::Getopt::Meta::Attribute - Optional meta attribute for custom option names
54 with 'MooseX::Getopt';
57 metaclass => 'MooseX::Getopt::Meta::Attribute',
60 default => 'file.dat',
62 # tells MooseX::Getopt to use --somedata as the
63 # command line flag instead of the normal
64 # autogenerated one (--data)
65 cmd_flag => 'somedata',
67 # tells MooseX::Getopt to also allow --moosedata,
68 # -m, and -d as aliases for this same option on
70 cmd_aliases => [qw/ moosedata m d /],
72 # Or, you can use a plain scalar for a single alias:
78 This is a custom attribute metaclass which can be used to specify a
79 the specific command line flag to use instead of the default one
80 which L<MooseX::Getopt> will create for you.
82 This is certainly not the prettiest way to go about this, but for
83 now it works for those who might need such a feature.
85 =head2 Custom Metaclass alias
87 This now takes advantage of the Moose 0.19 feature to support
88 custom attribute metaclass aliases. This means you can also
89 use this as the B<Getopt> alias, like so:
91 has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');
95 These methods are of little use to most users, they are used interally
96 within L<MooseX::Getopt>.
102 Changes the commandline flag to be this value, instead of the default,
103 which is the same as the attribute name.
107 Adds more aliases for this commandline flag, useful for short options
110 =item B<has_cmd_flag>
112 =item B<has_cmd_aliases>
120 All complex software has bugs lurking in it, and this module is no
121 exception. If you find a bug please either email me, or add the bug
126 Stevan Little E<lt>stevan@iinteractive.comE<gt>
128 Brandon L. Black, E<lt>blblack@gmail.comE<gt>
130 =head1 COPYRIGHT AND LICENSE
132 Copyright 2007 by Infinity Interactive, Inc.
134 L<http://www.iinteractive.com>
136 This library is free software; you can redistribute it and/or modify
137 it under the same terms as Perl itself.