Commando/Presenter.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 6 totaltotal 91.4% 64 / 70 CC 6 SCAR 5.9
CC
6
Cov
100%
command_presentation
3.0
options_presentation
2.0
subcommands_presentation
2.0
CRAP 1.8
« Commando/Logger.pm ↑ Summary Commando/Program.pm »
1 package App::Commando::Presenter;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 has 'command' => ( is => 'rw' );
10  
11 3 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
12 3 my ($class, $command) = @_;
13  
14 return {
15 3 command => $command,
16 };
17 }
18  
19 2 ▶sub usage_presentation {
Subroutine usage_presentation: called CC=1 SCAR=0.0
Pod undocumented
20 2 my ($self) = @_;
21  
22 2 return ' ' . $self->command->syntax;
23 }
24  
25 3 ▶sub options_presentation {
Subroutine options_presentation: called CC=2 SCAR=6.9
Pod undocumented
26 3 my ($self) = @_;
27  
28 3 ▶ return if !@{$self->command->options};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->command->options;} 1 2 3
29  
30 2 return join "\n", map { $_->as_string } @{$self->command->options};
31 }
32  
33 3 ▶sub subcommands_presentation {
Subroutine subcommands_presentation: called CC=2 SCAR=6.9
Pod undocumented
34 3 my ($self) = @_;
35  
36 3 ▶ return if !%{$self->command->commands};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$self->command->commands;} 1 2 3
37  
38 2 return join "\n", map { $_->summarize }
39 # Remove duplicate commands
40 2 values %{{
41 2 map { refaddr($_) => $_ } values %{$self->command->commands}
42 }};
43 }
44  
45 2 ▶sub command_header {
Subroutine command_header: called CC=2 SCAR=6.9
Pod undocumented
46 2 my ($self) = @_;
47  
48 2 my $header = $self->command->identity;
49 2 ▶ $header .= " -- " . $self->command->description
Branch: 1 branch
BranchTrueFalseTotal
if $self->command->description 1 1 2
50 if $self->command->description;
51  
52 2 return $header;
53 }
54  
55 2 ▶sub command_presentation {
Subroutine command_presentation: called CC=3 SCAR=11.0
Pod undocumented
56 2 my ($self) = @_;
57  
58 2 my @msg = ();
59  
60 2 push @msg,
61 $self->command_header,
62 'Usage:',
63 $self->usage_presentation;
64  
65 2 ▶ if (my $options = $self->options_presentation) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $options = $self->options_presentation) 1 1 2
66 1 push @msg, "Options:\n" . $options;
67 }
68  
69 2 ▶ if (my $subcommands = $self->subcommands_presentation) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $subcommands = $self->subcommands_presentation) 1 1 2
70 1 push @msg, "Subcommands:\n" . $subcommands;
71 }
72  
73 2 return join "\n\n", @msg;
74 }
75  
76 8 1;
77  
78 __END__
« Commando/Logger.pm ↑ Summary Commando/Program.pm »