File Coverage

blib/lib/MooX/Cmd/ChainedOptions/Base.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition n/a
subroutine 4 4 100.0
pod n/a
total 26 26 100.0


line stmt bran cond sub pod time code
1             package MooX::Cmd::ChainedOptions::Base;
2              
3             # ABSTRACT: anchor role for chained option roles
4              
5 2     2   6494 use Moo::Role;
  2         6  
  2         18  
6 2     2   820 use Scalar::Util qw[ blessed ];
  2         6  
  2         189  
7              
8 2     2   15 use namespace::clean;
  2         32  
  2         22  
9              
10             our $VERSION = '0.04';
11              
12             has _parent => (
13             is => 'lazy',
14             init_arg => undef,
15             builder => sub {
16              
17 13     13   301680 my $class = blessed $_[0];
18              
19             # Find the element in command chain array which directly
20             # precedes the element containing the current class.
21              
22             # There is a single array used for the command chain, and it
23             # is populated by MooX::Cmd as it processes the command line.
24             # This builder may be called for a class after MooX::Cmd has
25             # added entries for the class' subcommands, so we can't simply
26             # assume that the last element in the array is for this class.
27              
28 13         40 my $last;
29 13         34 for ( reverse @{ $_[0]->command_chain } ) {
  13         138  
30 28 100       148 next unless $last;
31 16 100       396 return $_ if blessed $last eq $class;
32             }
33 16         49 continue { $last = $_ }
34              
35 1         22 require Carp;
36 1         167 Carp::croak( "unable to determine parent in chain hierarchy\n" );
37             },
38             );
39              
40             1;
41              
42             #
43             # This file is part of MooX-Cmd-ChainedOptions
44             #
45             # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
46             #
47             # This is free software, licensed under:
48             #
49             # The GNU General Public License, Version 3, June 2007
50             #
51              
52             =pod
53              
54             =head1 NAME
55              
56             MooX::Cmd::ChainedOptions::Base - anchor role for chained option roles
57              
58             =head1 VERSION
59              
60             version 0.04
61              
62             =head1 DESCRIPTION
63              
64             This role provides the basis for the per-command roles generated by
65             L. It provides the C<_parent>
66             attribute which handles options further up the command chain.
67              
68             =head1 BUGS AND LIMITATIONS
69              
70             You can make new bug reports, and view existing ones, through the
71             web interface at L.
72              
73             =head1 SEE ALSO
74              
75             Please see those modules/websites for more information related to this module.
76              
77             =over 4
78              
79             =item *
80              
81             L
82              
83             =back
84              
85             =head1 AUTHOR
86              
87             Diab Jerius
88              
89             =head1 COPYRIGHT AND LICENSE
90              
91             This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
92              
93             This is free software, licensed under:
94              
95             The GNU General Public License, Version 3, June 2007
96              
97             =cut
98              
99             __END__