Cmd/Subdispatch.pm

filter: Statementstmt 71.0% 27 / 38 Branchbran 50.0% 4 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 72.7% 8 / 11 Podpod 100% 4 / 4 totaltotal 61.4% 43 / 70 CC 7 SCAR 18.1
CC
7
Cov
60%
choose_parent_app
20.0
prepare
3.0
new
2.5
CRAP 6.1
« Cmd/Command/commands.pm ↑ Summary Cmd/Command.pm »
1 # The "experimental" below is not actually scary. The feature went on to be
2 # de-experimental-ized with no changes and is now on by default in perl v5.24
3 # and later. -- rjbs, 2021-03-14
4 2 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use experimental qw(postderef postderef_qq);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package App::Cmd::Subdispatch 0.340;
9  
10 2 ▶use App::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use App::Cmd::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶BEGIN { our @ISA = qw(App::Cmd::Command App::Cmd) }
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # ABSTRACT: an App::Cmd::Command that is also an App::Cmd
15  
16 #pod =method new
17 #pod
18 #pod A hackish new that allows us to have an Command instance before they normally
19 #pod exist.
20 #pod
21 #pod =cut
22  
23 2 ▶sub new {
Subroutine new: called CC=2 SCAR=9.2
Pod documented
24 2 my ($inv, $fields, @args) = @_;
25 2 ▶ if (ref $inv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inv) { } 0 2 2
26 0 @{ $inv }{ keys %$fields } = values %$fields;
27 0 return $inv;
28 } else {
29 2 $inv->SUPER::new($fields, @args);
30 }
31 }
32  
33 #pod =method prepare
34 #pod
35 #pod my $subcmd = $subdispatch->prepare($app, @args);
36 #pod
37 #pod An overridden version of L<App::Cmd::Command/prepare> that performs a new
38 #pod dispatch cycle.
39 #pod
40 #pod =cut
41  
42 2 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.1
Pod documented
43 2 my ($class, $app, @args) = @_;
44  
45 2 my $self = $class->new({ app => $app });
46  
47 2 my ($subcommand, $opt, @sub_args) = $self->get_command(@args);
48  
49 2 $self->set_global_options($opt);
50  
51 2 ▶ if (defined $subcommand) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subcommand) { } 1 1 2
52 1 return $self->_prepare_command($subcommand, $opt, @sub_args);
53 } else {
54 1 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 0 1 1
55 0 return $self->_bad_command(undef, $opt, @sub_args);
56 } else {
57 1 return $self->_prepare_default_command($opt, @sub_args);
58 }
59 }
60 }
61  
62 0 ▶sub _plugin_prepare {
Subroutine _plugin_prepare: not called CC=1 SCAR=6.9
63 0 my ($self, $plugin, @args) = @_;
64 0 return $plugin->prepare($self->choose_parent_app($self->app, $plugin), @args);
65 }
66  
67 #pod =method app
68 #pod
69 #pod $subdispatch->app;
70 #pod
71 #pod This method returns the application that this subdispatch is a command of.
72 #pod
73 #pod =cut
74  
75 0 ▶sub app { $_[0]{app} }
Subroutine app: not called CC=1 SCAR=6.9
Pod documented
76  
77 #pod =method choose_parent_app
78 #pod
79 #pod $subcmd->prepare(
80 #pod $subdispatch->choose_parent_app($app, $opt, $plugin),
81 #pod @$args
82 #pod );
83 #pod
84 #pod A method that chooses whether the parent app or the subdispatch is going to be
85 #pod C<< $cmd->app >>.
86 #pod
87 #pod =cut
88  
89 0 ▶sub choose_parent_app {
Subroutine choose_parent_app: not called CC=4 SCAR=30.0
Pod documented
90 0 my ( $self, $app, $plugin ) = @_;
91  
92 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->isa('App::Cmd::Command::commands') or $plugin->isa('App::Cmd::Command::help') or keys %{$self->global_options}) { } 0 0 0
Condition0%0/6
$plugin->isa("App::Cmd::Command::commands") or $plugin->isa("App::Cmd::Command::help") or keys %{$self->global_options}
l!l&&r!l&&!r
000
$plugin->isa("App::Cmd::Command::commands") or $plugin->isa("App::Cmd::Command::help")
l!l&&r!l&&!r
000
MC/DC0%0/3
$plugin->isa("App::Cmd::Command::commands") or $plugin->isa("App::Cmd::Command::help") or keys %{$self->global_options}
$plugin->isa("App::Cmd::Command::commands") $plugin->isa("App::Cmd::Command::help") keys %{$self->global_options}
Truth table0%0/4
A or B or C
A= $plugin->isa("App::Cmd::Command::commands")B= $plugin->isa("App::Cmd::Command::help")C= keys %{$self->global_options}
ABCresult
1XX1
01X1
0011
0000
93 $plugin->isa("App::Cmd::Command::commands")
94 or $plugin->isa("App::Cmd::Command::help")
95 or keys $self->global_options->%*
96 ) {
97 0 return $self;
98 } else {
99 0 return $app;
100 }
101 }
102  
103 2 1;
104  
105 __END__
« Cmd/Command/commands.pm ↑ Summary Cmd/Command.pm »