V1/PredictionServiceClient.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« V1/AutoMlClient.pm ↑ Summary
1 package Google::Cloud::Automl::V1::PredictionServiceClient;
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 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use Google::gRPC::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Google::Cloud::REST::Client;
8 use Google::Auth;
9 use Carp qw(croak);
10  
11 use Protobuf;
12 use Google::Api::Common;
13 use Google::Cloud::Automl::V1::TextSegment;
14 use Google::Cloud::Automl::V1::Classification;
15 use Google::Cloud::Automl::V1::Geometry;
16 use Google::Cloud::Automl::V1::TextExtraction;
17 use Google::Cloud::Automl::V1::AnnotationSpec;
18 use Google::Cloud::Automl::V1::Io;
19 use Google::Cloud::Automl::V1::TextSentiment;
20 use Google::Cloud::Automl::V1::Image;
21 use Google::Cloud::Automl::V1::Text;
22 use Google::Cloud::Automl::V1::Detection;
23 use Google::Cloud::Automl::V1::Operations;
24 use Google::Cloud::Automl::V1::DataItems;
25 use Google::Cloud::Automl::V1::Translation;
26 use Google::Cloud::Automl::V1::AnnotationPayload;
27 use Google::Cloud::Automl::V1::Dataset;
28 use Google::Cloud::Automl::V1::ModelEvaluation;
29 use Google::Cloud::Automl::V1::Model;
30 use Google::Cloud::Automl::V1::PredictionService;
31 use Google::Cloud::Automl::V1::Service;
32  
33 our $VERSION = '0.06';
34  
35 has credentials => ( is => 'ro', required => 0 );
36 has transport => ( is => 'rw' );
37  
38 sub BUILD {
39 my ($self) = @_;
40  
41 my $auth = $self->credentials;
42 if (!defined $auth) {
43 $auth = Google::Auth->default();
44 } elsif (!eval { $auth->can('get_token') }) {
45 croak 'Invalid credentials object: must implement get_token()';
46 }
47 my $token = $auth->get_token();
48  
49 my $target = 'automl.googleapis.com:443';
50 my $t = $self->transport || 'grpc';
51  
52 if (ref($t) && eval { $t->can('call') }) {
53 # Already a transport object
54 } elsif (lc($t) eq 'rest') {
55 my $client = Google::Cloud::REST::Client->new(
56 target => $target,
57 auth_token => $token,
58 );
59 $self->transport($client);
60 } else {
61 my $client = Google::gRPC::Client->new(
62 target => $target,
63 auth_token => $token,
64 );
65 $self->transport($client);
66 }
67 }
68  
69 sub predict {
70 my ($self, %params) = @_;
71  
72 my $request_class = 'Google::Cloud::Automl::V1::PredictionService::PredictRequest';
73 my $request = eval { $request_class->new(\%params) };
74 my $new_err = $@;
75 if (!$request) {
76 $request = eval { $request_class->new(%params) };
77 $new_err ||= $@;
78 }
79 if (!$request) {
80 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
81 }
82  
83 my $response_class = 'Google::Cloud::Automl::V1::PredictionService::PredictResponse';
84 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
85 return $self->transport->call({
86 http_method => 'POST',
87 path => '/google.cloud.automl.v1.PredictionService/Predict',
88 request => $request,
89 response_class => $response_class,
90 });
91 }
92  
93 my $response = $self->transport->call({
94 service => 'google.cloud.automl.v1.PredictionService',
95 method => 'Predict',
96 request => $request,
97 response_class => $response_class,
98 });
99  
100 return $response;
101 }
102 1; # End of Google::Cloud::Automl::V1::PredictionServiceClient
103  
104 __END__
« V1/AutoMlClient.pm ↑ Summary