migrated repository to github moose organization
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Meta / Attribute / Trait.pm
CommitLineData
adbe3e57 1package MooseX::Getopt::Meta::Attribute::Trait;
669588e2 2# ABSTRACT: Optional meta attribute trait for custom option names
3
adbe3e57 4use Moose::Role;
5use Moose::Util::TypeConstraints;
6
adbe3e57 7has 'cmd_flag' => (
8 is => 'rw',
9 isa => 'Str',
10 predicate => 'has_cmd_flag',
11);
12
13# This subtype is to support scalar -> arrayref coercion
14# without polluting the built-in types
15subtype '_MooseX_Getopt_CmdAliases' => as 'ArrayRef';
669588e2 16
adbe3e57 17coerce '_MooseX_Getopt_CmdAliases'
18 => from 'Str'
19 => via { [$_] };
20
21has 'cmd_aliases' => (
22 is => 'rw',
23 isa => '_MooseX_Getopt_CmdAliases',
24 predicate => 'has_cmd_aliases',
25 coerce => 1,
26);
27
669588e2 28no Moose::Util::TypeConstraints;
adbe3e57 29no Moose::Role;
30
31# register this as a metaclass alias ...
669588e2 32package # stop confusing PAUSE
adbe3e57 33 Moose::Meta::Attribute::Custom::Trait::Getopt;
34sub register_implementation { 'MooseX::Getopt::Meta::Attribute::Trait' }
35
361;
37
adbe3e57 38=head1 SYNOPSIS
39
40 package App;
41 use Moose;
669588e2 42
adbe3e57 43 with 'MooseX::Getopt';
669588e2 44
adbe3e57 45 has 'data' => (
669588e2 46 traits => [ 'Getopt' ],
adbe3e57 47 is => 'ro',
48 isa => 'Str',
49 default => 'file.dat',
50
669588e2 51 # tells MooseX::Getopt to use --somedata as the
52 # command line flag instead of the normal
adbe3e57 53 # autogenerated one (--data)
54 cmd_flag => 'somedata',
55
56 # tells MooseX::Getopt to also allow --moosedata,
57 # -m, and -d as aliases for this same option on
58 # the commandline.
59 cmd_aliases => [qw/ moosedata m d /],
60
61 # Or, you can use a plain scalar for a single alias:
62 cmd_aliases => 'm',
63 );
64
65=head1 DESCRIPTION
66
669588e2 67This is a custom attribute metaclass trait which can be used to
68specify a the specific command line flag to use instead of the
69default one which L<MooseX::Getopt> will create for you.
adbe3e57 70
669588e2 71=method B<cmd_flag>
adbe3e57 72
73Changes the commandline flag to be this value, instead of the default,
74which is the same as the attribute name.
75
669588e2 76=method B<cmd_aliases>
adbe3e57 77
78Adds more aliases for this commandline flag, useful for short options
79and such.
80
669588e2 81=method B<has_cmd_flag>
adbe3e57 82
669588e2 83=method B<has_cmd_aliases>
adbe3e57 84
85=cut