Cmd/SpecifiedEntries.pm

filter: Statementstmt 60.0% 18 / 30 Branchbran 37.5% 3 / 8 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 50.0% 26 / 52 CC 7 SCAR 28.6
CC
7
Cov
50%
_build_entries
24.5
BEGIN
1.0
BEGIN
1.0
CRAP 17.5
« Cmd/OutputHandle.pm ↑ Summary Cmd/WithDSN/Create.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Cmd::SpecifiedEntries;
4 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Data::Stream::Bulk::Util qw(bulk);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #with qw(KiokuDB::Cmd::WithDSN); # attributes don't recompose well
11 #requires 'backend';
12  
13 1 has ids => (
14 traits => [qw(Getopt)],
15 does => "ArrayRef[Str]",
16 is => "ro",
17 predicate => "has_ids",
18 cmd_aliases => "i",
19 documentation => "specify entries (can be used multiple times)",
20 );
21  
22 1 has entries => (
23 traits => [qw(NoGetopt)],
24 does => "Data::Stream::Bulk",
25 is => "ro",
26 lazy_build => 1,
27 );
28  
29 1 has entries_in_args => (
30 traits => [qw(NoGetopt)],
31 isa => "Bool",
32 is => "ro",
33 default => 0,
34 );
35  
36 3 ▶sub _build_entries {
Subroutine _build_entries: called CC=7 SCAR=32.0
37 3 my $self = shift;
38  
39 3 my ( @ids, @entries );
40  
41 3 ▶ if ( $self->has_ids ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_ids) { } 0 3 3
elsif ($self->entries_in_args and my $args = $self->args) { } 0 3 3
42 0 @ids = @{ $self->ids };
43 ▶ } elsif ( $self->entries_in_args and my $args = $self->args ) {
Condition33%1/3
$self->entries_in_args and my $args = $self->args
!ll&&!rl&&r
030
MC/DC0%0/2
$self->entries_in_args and my $args = $self->args
$self->entries_in_args my $args = $self->args
Truth table33%1/3
A and B
A= $self->entries_in_argsB= my $args = $self->args
ABresult
0X0
100
111
44 0 @ids = @$args;
45 }
46  
47 3 ▶ if ( @ids ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ids) { } 0 3 3
48 0 @entries = $self->backend->get(@ids);
49  
50 0 ▶ if ( @entries != @ids or grep { not defined } @entries ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@entries != @ids or grep {not defined $_;} @entries) 0 0 0
Condition0%0/3
@entries != @ids or grep {not defined $_;} @entries
l!l&&r!l&&!r
000
MC/DC0%0/2
@entries != @ids or grep {not defined $_;} @entries
@entries != @ids grep {not defined $_;} @entries
Truth table0%0/3
A or B
A= @entries != @idsB= grep {not defined $_;} @entries
ABresult
1X1
011
000
51 0 my %exists;
52 0 @exists{@ids} = $self->backend->exists(@ids);
53  
54 0 my @missing = grep { not $exists{$_} } @ids;
55  
56 0 die "The specified entries do not exist in the database: @missing\n";
57 }
58  
59 0 return bulk(@entries);
60 } else {
61 3 return $self->backend->all_entries;
62 }
63 }
64  
65 1 __PACKAGE__
66  
67 __END__
« Cmd/OutputHandle.pm ↑ Summary Cmd/WithDSN/Create.pm »