CLI/Command/Search.pm

filter: Statementstmt 36.3% 12 / 33 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 29.2% 19 / 65 CC 10 SCAR 42.4
CC
10
Cov
24%
execute
110.0
abstract
2.0
opt_spec
2.0
CRAP 69.2
↑ Summary CLI/Command/Remove.pm »
1 package Luv::CLI::Command::Search;
2  
3 # ABSTRACT: search the library registry
4  
5 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use App::Cmd::Setup -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Luv::CLI::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub abstract {"Searches the local library registry."}
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
13  
14 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
15 return (
16 0 [ 'update' => 'refresh the registry before searching' ],
17 [ 'all|a' => 'list all libraries in the local registry cache' ],
18 );
19 }
20  
21 0 ▶sub execute ( $self, $opt, $args ) {
Subroutine execute: not called CC=10 SCAR=47.0
Pod documented
22 0 my $cache_path = File::HomeDir->my_home . '/.cache/luv/registry.json';
23 0 my $registry = Luv::CLI::Registry->new( cache_path => $cache_path );
24  
25 0 ▶ if ( $opt->{update} || $registry->is_stale ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'update'} or $registry->is_stale) { } 0 0 0
Condition0%0/3
$opt->{"update"} or $registry->is_stale
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{"update"} or $registry->is_stale
$opt->{"update"} $registry->is_stale
Truth table0%0/3
A or B
A= $opt->{"update"}B= $registry->is_stale
ABresult
1X1
011
000
26 0 print "Refreshing registry...\n";
27 0 $registry->refresh;
28 }
29 else {
30 0 $registry->load;
31 }
32  
33 0 my @matches;
34 0 ▶ if ( $opt->{all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'all'}) { } 0 0 0
35 0 @matches = $registry->all_entries;
36 }
37 else {
38 0 ▶ my $term = $args->[0] or die "Usage: luv search <term> | --all\n";
Branch: 1 branch
BranchTrueFalseTotal
my $term = $args->[0] or die "Usage: luv search <term> | --all\n" 0 0 0
39 0 @matches = $registry->search($term);
40 }
41  
42 0 ▶ if ( !@matches ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@matches) 0 0 0
43 0 print "No libraries found\n";
44 0 return;
45 }
46  
47 0 ▶ for my $m ( sort { ( $a->{name} // '' ) cmp ( $b->{name} // '' ) }
Condition0%0/4
$Luv::CLI::Command::Search::a->{"name"} // ""
l!l
00
$Luv::CLI::Command::Search::b->{"name"} // ""
l!l
00
MC/DC0%0/1
$Luv::CLI::Command::Search::a->{"name"} // ""
$Luv::CLI::Command::Search::a->{"name"}
MC/DC0%0/1
$Luv::CLI::Command::Search::b->{"name"} // ""
$Luv::CLI::Command::Search::b->{"name"}
Truth table0%0/2
A
A= $Luv::CLI::Command::Search::a->{"name"}
Aresult
11
00
Truth table0%0/2
A
A= $Luv::CLI::Command::Search::b->{"name"}
Aresult
11
00
48 @matches )
49 {
50 0 ▶ my $name = $m->{name} // '(unknown)';
Condition0%0/2
$m->{"name"} // "(unknown)"
l!l
00
MC/DC0%0/1
$m->{"name"} // "(unknown)"
$m->{"name"}
Truth table0%0/2
A
A= $m->{"name"}
Aresult
11
00
51 0 print "$name — $m->{description}\n $m->{url}\n\n";
52 }
53  
54 0 return;
55 }
56  
57 1 1;
58  
59 __END__
↑ Summary CLI/Command/Remove.pm »