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

filter: Statementstmt 100% 19 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 25 / 25 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
__ANON__
1.0
CRAP 1.0
« blib/lib/MouseX/Getopt/Meta/Attribute/NoGetopt.pm ↑ Summary blib/lib/MouseX/Getopt/Meta/Attribute/Trait/NoGetopt.pm »
1 package MouseX::Getopt::Meta::Attribute::Trait;
2 # ABSTRACT: Optional meta attribute trait for custom option names
3  
4 22 ▶use Mouse::Role;
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 has '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
15 22 subtype '_MouseX_Getopt_CmdAliases' => as 'ArrayRef';
16  
17 coerce '_MouseX_Getopt_CmdAliases'
18 => from 'Str'
19 7 ▶ => via { [$_] };
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 22 has 'cmd_aliases' => (
22 is => 'rw',
23 isa => '_MouseX_Getopt_CmdAliases',
24 predicate => 'has_cmd_aliases',
25 coerce => 1,
26 );
27  
28 22 ▶no Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 22 ▶no Mouse::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # register this as a metaclass alias ...
32 package # stop confusing PAUSE
33 Mouse::Meta::Attribute::Custom::Trait::Getopt;
34 20 ▶sub register_implementation { 'MouseX::Getopt::Meta::Attribute::Trait' }
Subroutine register_implementation: called CC=1 SCAR=0.0
35  
36 22 1;
37  
38 =for stopwords metaclass commandline params configfile
39  
40 =head1 SYNOPSIS
41  
42 package App;
43 use Mouse;
44  
45 with 'MouseX::Getopt';
46  
47 has 'data' => (
48 traits => [ 'Getopt' ],
49 is => 'ro',
50 isa => 'Str',
51 default => 'file.dat',
52  
53 # tells MouseX::Getopt to use --somedata as the
54 # command line flag instead of the normal
55 # autogenerated one (--data)
56 cmd_flag => 'somedata',
57  
58 # tells MouseX::Getopt to also allow --moosedata,
59 # -m, and -d as aliases for this same option on
60 # the commandline.
61 cmd_aliases => [qw/ moosedata m d /],
62  
63 # Or, you can use a plain scalar for a single alias:
64 cmd_aliases => 'm',
65 );
66  
67 =head1 DESCRIPTION
68  
69 This is a custom attribute metaclass trait which can be used to
70 specify a the specific command line flag to use instead of the
71 default one which L<MouseX::Getopt> will create for you.
72  
73 =over 4
74  
75 =item B<cmd_flag>
76  
77 Changes the commandline flag to be this value, instead of the default,
78 which is the same as the attribute name.
79  
80 =item B<cmd_aliases>
81  
82 Adds more aliases for this commandline flag, useful for short options
83 and such.
84  
85 =item B<has_cmd_flag>
86  
87 =item B<has_cmd_aliases>
88  
89 =back
90  
91 =cut
« blib/lib/MouseX/Getopt/Meta/Attribute/NoGetopt.pm ↑ Summary blib/lib/MouseX/Getopt/Meta/Attribute/Trait/NoGetopt.pm »