| 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 44 | 0 | @ids = @$args; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | if ( @ids ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | @entries = $self->backend->get(@ids); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( @entries != @ids or grep { not defined } @entries ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@entries != @ids or grep {not defined $_;} @entries
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||