lib/CLI/Framework/Command/Tree.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 100% 6 / 6 Conditioncond 85.7% 6 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 87.5% 7 / 8 Podpod 66.6% 2 / 3 totaltotal 91.8% 68 / 74 CC 8 SCAR 15.7
CC
8
Cov
97%
command_tree
8.0
usage_text
2.0
BEGIN
1.0
CRAP 4.8
« lib/CLI/Framework/Command.pm ↑ Summary blib/lib/CLI/Framework/Command/List.pm »
1 package CLI::Framework::Command::Tree;
2 1 ▶use base qw( CLI::Framework::Command::Meta );
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 0.01;
8  
9 #-------
10  
11 sub usage_text {
12 0 ▶ q{
Subroutine usage_text: not called CC=1 SCAR=6.9
Pod documented
13 tree: tree view of the names of only those commands that are currently registered in the application
14 }
15 }
16  
17 sub run {
18 1 ▶ my ($self, $opts, @args) = @_;
Subroutine run: called CC=1 SCAR=0.0
Pod documented
19
20 1 my $app = $self->get_app(); # metacommand is app-aware
21  
22 1 my $tree = command_tree( $app );
23 1 $tree =~ s/^/\t/gm;
24 1 return $tree;
25 }
26  
27 #-------
28  
29 sub command_tree {
30 10 ▶ my ($app, $root, $indent, $tree) = @_;
Subroutine command_tree: called CC=8 SCAR=20.8
Pod undocumented
31  
32 10 ▶ $root ||= $app;
Condition66%2/3
$root ||= $app
l!l&&r!l&&!r
910
MC/DC0%0/2
$root ||= $app
$root $app
Truth table66%2/3
A ||= B
A= $rootB= $app
ABresult
1X1
011
000
33 10 ▶ $indent ||= 0;
Condition100%2/2
$indent ||= 0
l!l
64
MC/DC100%1/1
$indent ||= 0
$indent
Truth table100%2/2
A
A= $indent
Aresult
11
00
34  
35 # (output object)
36 10 ▶ $tree = { text => '' } unless ref $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tree 1 9 10
37  
38 10 ▶ $indent += 4 if( $root->isa( 'CLI::Framework::Command' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $root->isa("CLI::Framework::Command") 9 1 10
39  
40 # For every command registered into the root object (either a CLIF
41 # Application or a CLIF Command), append its tree representation to the
42 # output object...
43  
44 # Use proper accessors for object type...
45 10 my $registered_command_names_accessor = 'registered_command_names';
46 10 my $registered_command_obj_accessor = 'registered_command_object';
47 10 ▶ if( $root->isa('CLI::Framework::Command') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->isa("CLI::Framework::Command")) 9 1 10
48 9 $registered_command_names_accessor = 'registered_subcommand_names';
49 9 $registered_command_obj_accessor = 'registered_subcommand_object';
50 }
51 10 my @command_names;
52 1 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
53 10 @command_names = $root->$registered_command_names_accessor;
54 }
55 10 for my $command_name (@command_names) {
56 #XXX-ALTERNATIVE: show a tree of command names
57 # $tree->{text} .= ' 'x$indent . $command_name . "\n";
58  
59 9 my $command_obj;
60 1 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 9 $command_obj = $root->$registered_command_obj_accessor( $command_name );
62 }
63  
64 #XXX-ALTERNATIVE: show a tree of Perl package names defining the commands (including
65 # source files they were defined in):
66 9 my $source = Class::Inspector->loaded_filename( ref $command_obj );
67 9 ▶$source ||= 'defined inline';
Condition100%2/2
$source ||= "defined inline"
l!l
63
MC/DC100%1/1
$source ||= "defined inline"
$source
Truth table100%2/2
A
A= $source
Aresult
11
00
68 9 my $x = ref ($command_obj) . " ($source)";
69 9 $tree->{text} .= ' 'x$indent . $x . "\n";
70  
71 # Recursive call (NOTE: passing output object reference which will act
72 # as an accumulator)...
73 9 command_tree( $app, $command_obj, $indent, $tree );
74 }
75 10 return $tree->{text} . "\n";
76 }
77  
78 #-------
79 1 1;
80  
81 __END__
« lib/CLI/Framework/Command.pm ↑ Summary blib/lib/CLI/Framework/Command/List.pm »