blib/lib/OpenAPI/Client/Pinecone.pm

filter: Statementstmt 58.4% 31 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 100% 1 / 1 totaltotal 48.7% 40 / 82 SCAR 29.1
CC
8
Cov
46%
new
72.0
__ANON__
2.0
__ANON__
2.0
CRAP 18.3
↑ Summary
1 package OpenAPI::Client::Pinecone;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::ShareDir ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Mojo::Base 'OpenAPI::Client';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '0.02';
14  
15 sub new {
16 0 ▶ my ( $class, $specification ) = ( shift, shift );
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
17 0 ▶ my $attrs = @_ == 1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
18  
19 0 ▶ if ( !$ENV{PINECONE_API_KEY} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PINECONE_API_KEY"}) 0 0 0
20 0 Carp::croak('PINECONE_API_KEY environment variable must be set');
21 }
22  
23 0 ▶ if ( !$ENV{PINECONE_API_KEY} && !$attrs->{base_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PINECONE_API_KEY"} or $attrs->{"base_url"}) 0 0 0
Condition0%0/3
$ENV{"PINECONE_API_KEY"} or $attrs->{"base_url"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"PINECONE_API_KEY"} or $attrs->{"base_url"}
$ENV{"PINECONE_API_KEY"} $attrs->{"base_url"}
Truth table0%0/3
A or B
A= $ENV{"PINECONE_API_KEY"}B= $attrs->{"base_url"}
ABresult
1X1
011
000
24 0 Carp::croak('PINECONE_API_KEY environment variable must be set');
25 }
26  
27 0 ▶ if ( !$specification ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($specification) 0 0 0
28 eval {
29 0 $specification = dist_file( 'OpenAPI-Client-Pinecone', 'pinecone.yaml' );
30 0 1;
31 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $specification = dist_file("OpenAPI-Client-Pinecone", "pinecone.yaml"); 1 } } or do { warn $@; $specification = catfile("share", "pinecone.yaml") } 0 0 0
32 # Fallback to local share directory during development
33 0 warn $@;
34 0 $specification = catfile( 'share', 'pinecone.yaml' );
35 };
36 }
37  
38 0 my $self = $class->SUPER::new( $specification, %{$attrs} );
39  
40 $self->ua->on(
41 start => sub {
42 0 ▶ my ( $ua, $tx ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 $tx->req->headers->header( 'Api-Key' => $ENV{PINECONE_API_KEY} );
44 }
45 0 );
46  
47 0 ▶ if ( !$attrs->{base_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attrs->{"base_url"}) 0 0 0
48 0 $self->base_url( Mojo::URL->new("https://controller.$ENV{PINECONE_ENVIRONMENT}.pinecone.io") );
49 }
50  
51 0 return $self;
52 }
53  
54 # install snake case aliases
55  
56 {
57 1 my %snake_case_alias = (
58 DescribeIndexStats => 'describe_index_stats',
59 Query => 'query',
60 Delete => 'delete_vector',
61 Fetch => 'fetch_vector',
62 Update => 'update_vector',
63 Upsert => 'upsert_vector',
64 );
65  
66 1 for my $camel_case_method ( keys %snake_case_alias ) {
67 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
68 6 *{"$snake_case_alias{$camel_case_method}"} = sub {
69 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 $self->$camel_case_method(@_);
71 }
72 6 }
73 }
74  
75 1 1;
76  
77 __END__
↑ Summary