line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Getopt::Meta::Attribute; |
2
|
|
|
|
|
|
|
# ABSTRACT: Optional meta attribute for custom option names |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.75'; |
5
|
|
|
|
|
|
|
|
6
|
27
|
|
|
27
|
|
201
|
use Moose; |
|
27
|
|
|
|
|
55
|
|
|
27
|
|
|
|
|
195
|
|
7
|
27
|
|
|
27
|
|
179324
|
use namespace::autoclean; |
|
27
|
|
|
|
|
70
|
|
|
27
|
|
|
|
|
262
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Moose::Meta::Attribute'; # << Moose extending Moose :) |
10
|
|
|
|
|
|
|
with 'MooseX::Getopt::Meta::Attribute::Trait'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# register this as a metaclass alias ... |
13
|
|
|
|
|
|
|
package # stop confusing PAUSE |
14
|
|
|
|
|
|
|
Moose::Meta::Attribute::Custom::Getopt; |
15
|
1
|
|
|
1
|
|
4765
|
sub register_implementation { 'MooseX::Getopt::Meta::Attribute' } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
1; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__END__ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=pod |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=encoding UTF-8 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
MooseX::Getopt::Meta::Attribute - Optional meta attribute for custom option names |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 VERSION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
version 0.75 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package App; |
36
|
|
|
|
|
|
|
use Moose; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
with 'MooseX::Getopt'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'data' => ( |
41
|
|
|
|
|
|
|
metaclass => 'Getopt', |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Str', |
44
|
|
|
|
|
|
|
default => 'file.dat', |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# tells MooseX::Getopt to use --somedata as the |
47
|
|
|
|
|
|
|
# command line flag instead of the normal |
48
|
|
|
|
|
|
|
# autogenerated one (--data) |
49
|
|
|
|
|
|
|
cmd_flag => 'somedata', |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# tells MooseX::Getopt to also allow --moosedata, |
52
|
|
|
|
|
|
|
# -m, and -d as aliases for this same option on |
53
|
|
|
|
|
|
|
# the commandline. |
54
|
|
|
|
|
|
|
cmd_aliases => [qw/ moosedata m d /], |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Or, you can use a plain scalar for a single alias: |
57
|
|
|
|
|
|
|
cmd_aliases => 'm', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This is a custom attribute metaclass which can be used to specify a |
63
|
|
|
|
|
|
|
the specific command line flag to use instead of the default one |
64
|
|
|
|
|
|
|
which L<MooseX::Getopt> will create for you. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This is certainly not the prettiest way to go about this, but for |
67
|
|
|
|
|
|
|
now it works for those who might need such a feature. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 Use 'traits' instead of 'metaclass' |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
You should rarely need to explicitly set the attribute metaclass. It is much |
72
|
|
|
|
|
|
|
preferred to simply provide a trait (a role applied to the attribute |
73
|
|
|
|
|
|
|
metaclass), which allows other code to further modify the attribute by applying |
74
|
|
|
|
|
|
|
additional roles. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Therefore, you should first try to do this: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has 'foo' => (traits => ['Getopt'], cmd_flag => 'f'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 Custom Metaclass alias |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This now takes advantage of the Moose 0.19 feature to support |
83
|
|
|
|
|
|
|
custom attribute metaclass aliases. This means you can also |
84
|
|
|
|
|
|
|
use this as the B<Getopt> alias, like so: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f'); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 B<cmd_flag> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Changes the command-line flag to be this value, instead of the default, |
93
|
|
|
|
|
|
|
which is the same as the attribute name. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 B<cmd_aliases> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Adds more aliases for this command-line flag, useful for short options |
98
|
|
|
|
|
|
|
and such. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 B<has_cmd_flag> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 B<has_cmd_aliases> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Getopt> |
107
|
|
|
|
|
|
|
(or L<bug-MooseX-Getopt@rt.cpan.org|mailto:bug-MooseX-Getopt@rt.cpan.org>). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
110
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
113
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Infinity Interactive, Inc. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
124
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |