line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# --8<--8<--8<--8<-- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (C) 2015 Smithsonian Astrophysical Observatory |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This file is part of MooX-Cmd-ChainedOptions |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# MooX-Cmd-ChainedOptions is free software: you can redistribute it and/or modify |
8
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
9
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or (at |
10
|
|
|
|
|
|
|
# your option) any later version. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
13
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
|
|
|
|
# GNU General Public License for more details. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
18
|
|
|
|
|
|
|
# along with this program. If not, see . |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# -->8-->8-->8-->8-- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package MooX::Cmd::ChainedOptions::Base; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
1523
|
use Moo::Role; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
25
|
2
|
|
|
2
|
|
456
|
use Scalar::Util qw[ blessed ]; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
294
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has _parent => ( |
28
|
|
|
|
|
|
|
is => 'lazy', |
29
|
|
|
|
|
|
|
init_arg => undef, |
30
|
|
|
|
|
|
|
builder => sub { |
31
|
|
|
|
|
|
|
|
32
|
13
|
|
|
13
|
|
64571
|
my $class = blessed $_[0]; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Find the element in command chain array which directly |
35
|
|
|
|
|
|
|
# precedes the element containing the current class. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# There is a single array used for the command chain, and it |
38
|
|
|
|
|
|
|
# is populated by MooX::Cmd as it processes the command line. |
39
|
|
|
|
|
|
|
# This builder may be called for a class after MooX::Cmd has |
40
|
|
|
|
|
|
|
# added entries for the class' subcommands, so we can't simply |
41
|
|
|
|
|
|
|
# assume that the last element in the array is for this class. |
42
|
|
|
|
|
|
|
|
43
|
13
|
|
|
|
|
58
|
my $last; |
44
|
13
|
|
|
|
|
18
|
for ( reverse @{ $_[0]->command_chain } ) { |
|
13
|
|
|
|
|
57
|
|
45
|
28
|
100
|
|
|
|
59
|
next unless $last; |
46
|
16
|
100
|
|
|
|
286
|
return $_ if blessed $last eq $class; |
47
|
|
|
|
|
|
|
} |
48
|
16
|
|
|
|
|
28
|
continue { $last = $_ } |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
6
|
require Carp; |
51
|
1
|
|
|
|
|
104
|
Carp::croak( "unable to determine parent in chain hierarchy\n" ); |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |