Typesense/Collection.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 91.0% 61 / 67 CC 8 SCAR 8.8
CC
8
Cov
90%
create
4.0
search
3.2
get
2.0
CRAP 2.4
« Typesense/Role/Request.pm ↑ Summary Typesense/Version.pm »
1 package Search::Typesense::Collection;
2  
3 # ABSTRACT: Collection - CRUD for Typesense collections
4  
5 4 ▶use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 with qw(Search::Typesense::Role::Request);
9  
10 4 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Search::Typesense::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 HashRef
13 InstanceOf
14 NonEmptyStr
15 Str
16 compile
17 4 );
18  
19  
20 4 our $VERSION = '0.08';
21  
22  
23 2 ▶sub search {
Subroutine search: called CC=3 SCAR=11.6
Pod documented
24 2 my ( $self, $collection, $query ) = @_;
25 2 state $check = compile( NonEmptyStr, HashRef );
26 2 ( $collection, $query ) = $check->( $collection, $query );
27  
28 2 ▶ unless ( exists $query->{q} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $query->{"q"}) 0 2 2
29 0 croak("Query parameter 'q' is required for searching");
30 }
31 2 ▶ my $tx = $self->_GET(
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->_GET("path", ["collections", $collection, "documents", "search"], "query", $query, "return_transaction", 1) or return 2 0 2
32 path => [ 'collections', $collection, 'documents', 'search' ],
33 query => $query,
34 return_transaction => 1,
35 ) or return;
36 2 return $tx->res->json;
37 }
38  
39 9 ▶sub get {
Subroutine get: called CC=2 SCAR=7.0
Pod documented
40 9 my ( $self, $collection ) = @_;
41 9 state $check = compile(Str);
42 9 ▶ my @collection = $check->( $collection // '' );
Condition50%1/2
$collection // ""
l!l
09
MC/DC0%0/1
$collection // ""
$collection
Truth table50%1/2
A
A= $collection
Aresult
11
00
43 9 return $self->_GET( path => [ 'collections', @collection ] );
44 }
45  
46  
47 2 ▶sub create {
Subroutine create: called CC=4 SCAR=13.9
Pod documented
48 2 my ( $self, $collection_definition ) = @_;
49 2 state $check = compile(HashRef);
50 2 ($collection_definition) = $check->($collection_definition);
51 2 my $fields = $collection_definition->{fields};
52  
53 2 foreach my $field (@$fields) {
54 6 ▶ if ( exists $field->{facet} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $field->{"facet"}) 6 0 6
55 $field->{facet}
56 6 ▶ = $field->{facet} ? Mojo::JSON->true : Mojo::JSON->false;
Branch: 1 branch
BranchTrueFalseTotal
$field->{'facet'} ? : 2 4 6
57 }
58 }
59  
60 2 return $self->_POST(
61 path => ['collections'],
62 body => $collection_definition
63 );
64 }
65  
66  
67 2 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
68 2 my ( $self, $collection ) = @_;
69 2 state $check = compile(NonEmptyStr);
70 2 ($collection) = $check->($collection);
71 2 return $self->_DELETE( path => [ 'collections', $collection ] );
72 }
73  
74  
75 7 ▶sub delete_all {
Subroutine delete_all: called CC=2 SCAR=6.9
Pod documented
76 7 my ($self) = @_;
77 7 my $collections = $self->get;
78 7 foreach my $collection (@$collections) {
79 2 my $name = $collection->{name};
80 2 $self->delete($name);
81 }
82 }
83  
84 4 1;
85  
86 __END__
« Typesense/Role/Request.pm ↑ Summary Typesense/Version.pm »