blib/lib/MouseX/Getopt/Meta/Attribute.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 17 / 17 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/MouseX/Getopt.pm ↑ Summary blib/lib/MouseX/Getopt/Meta/Attribute/NoGetopt.pm »
1 package MouseX::Getopt::Meta::Attribute;
2 # ABSTRACT: Optional meta attribute for custom option names
3  
4 22 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 extends 'Mouse::Meta::Attribute'; # << Mouse extending Mouse :)
8 22 with 'MouseX::Getopt::Meta::Attribute::Trait';
9  
10 22 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # register this as a metaclass alias ...
13 package # stop confusing PAUSE
14 Mouse::Meta::Attribute::Custom::Getopt;
15 5 ▶sub register_implementation { 'MouseX::Getopt::Meta::Attribute' }
Subroutine register_implementation: called CC=1 SCAR=0.0
16  
17 22 1;
18  
19 =for stopwords metaclass commandline params configfile
20  
21 =head1 SYNOPSIS
22  
23 package App;
24 use Mouse;
25  
26 with 'MouseX::Getopt';
27  
28 has 'data' => (
29 metaclass => 'MouseX::Getopt::Meta::Attribute',
30 is => 'ro',
31 isa => 'Str',
32 default => 'file.dat',
33  
34 # tells MouseX::Getopt to use --somedata as the
35 # command line flag instead of the normal
36 # autogenerated one (--data)
37 cmd_flag => 'somedata',
38  
39 # tells MouseX::Getopt to also allow --moosedata,
40 # -m, and -d as aliases for this same option on
41 # the commandline.
42 cmd_aliases => [qw/ moosedata m d /],
43  
44 # Or, you can use a plain scalar for a single alias:
45 cmd_aliases => 'm',
46 );
47  
48 =head1 DESCRIPTION
49  
50 This is a custom attribute metaclass which can be used to specify a
51 the specific command line flag to use instead of the default one
52 which L<MouseX::Getopt> will create for you.
53  
54 This is certainly not the prettiest way to go about this, but for
55 now it works for those who might need such a feature.
56  
57 =head2 Custom Metaclass alias
58  
59 This now takes advantage of the Moose 0.19 feature to support
60 custom attribute metaclass aliases. This means you can also
61 use this as the B<Getopt> alias, like so:
62  
63 has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');
64  
65 =over 4
66  
67 =item B<cmd_flag>
68  
69 Changes the commandline flag to be this value, instead of the default,
70 which is the same as the attribute name.
71  
72 =item B<cmd_aliases>
73  
74 Adds more aliases for this commandline flag, useful for short options
75 and such.
76  
77 =item B<has_cmd_flag>
78  
79 =item B<has_cmd_aliases>
80  
81 =back
82  
83 =cut
« blib/lib/MouseX/Getopt.pm ↑ Summary blib/lib/MouseX/Getopt/Meta/Attribute/NoGetopt.pm »