V1beta1/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
« V1beta1/AutoMlClient.pm ↑ Summary
1 package Google::Cloud::Automl::V1beta1::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::V1beta1::DataTypes;
14 use Google::Cloud::Automl::V1beta1::Io;
15 use Google::Cloud::Automl::V1beta1::Geometry;
16 use Google::Cloud::Automl::V1beta1::TextSegment;
17 use Google::Cloud::Automl::V1beta1::Regression;
18 use Google::Cloud::Automl::V1beta1::DataStats;
19 use Google::Cloud::Automl::V1beta1::Ranges;
20 use Google::Cloud::Automl::V1beta1::Temporal;
21 use Google::Cloud::Automl::V1beta1::Detection;
22 use Google::Cloud::Automl::V1beta1::TextExtraction;
23 use Google::Cloud::Automl::V1beta1::AnnotationSpec;
24 use Google::Cloud::Automl::V1beta1::TableSpec;
25 use Google::Cloud::Automl::V1beta1::ColumnSpec;
26 use Google::Cloud::Automl::V1beta1::DataItems;
27 use Google::Cloud::Automl::V1beta1::Classification;
28 use Google::Cloud::Automl::V1beta1::Translation;
29 use Google::Cloud::Automl::V1beta1::TextSentiment;
30 use Google::Cloud::Automl::V1beta1::Text;
31 use Google::Cloud::Automl::V1beta1::Image;
32 use Google::Cloud::Automl::V1beta1::Video;
33 use Google::Cloud::Automl::V1beta1::Tables;
34 use Google::Cloud::Automl::V1beta1::AnnotationPayload;
35 use Google::Cloud::Automl::V1beta1::Model;
36 use Google::Cloud::Automl::V1beta1::ModelEvaluation;
37 use Google::Cloud::Automl::V1beta1::Dataset;
38 use Google::Cloud::Automl::V1beta1::Operations;
39 use Google::Cloud::Automl::V1beta1::Service;
40 use Google::Cloud::Automl::V1beta1::PredictionService;
41  
42 our $VERSION = '0.06';
43  
44 has credentials => ( is => 'ro', required => 0 );
45 has transport => ( is => 'rw' );
46  
47 sub BUILD {
48 my ($self) = @_;
49  
50 my $auth = $self->credentials;
51 if (!defined $auth) {
52 $auth = Google::Auth->default();
53 } elsif (!eval { $auth->can('get_token') }) {
54 croak 'Invalid credentials object: must implement get_token()';
55 }
56 my $token = $auth->get_token();
57  
58 my $target = 'automl.googleapis.com:443';
59 my $t = $self->transport || 'grpc';
60  
61 if (ref($t) && eval { $t->can('call') }) {
62 # Already a transport object
63 } elsif (lc($t) eq 'rest') {
64 my $client = Google::Cloud::REST::Client->new(
65 target => $target,
66 auth_token => $token,
67 );
68 $self->transport($client);
69 } else {
70 my $client = Google::gRPC::Client->new(
71 target => $target,
72 auth_token => $token,
73 );
74 $self->transport($client);
75 }
76 }
77  
78 sub predict {
79 my ($self, %params) = @_;
80  
81 my $request_class = 'Google::Cloud::Automl::V1beta1::PredictionService::PredictRequest';
82 my $request = eval { $request_class->new(\%params) };
83 my $new_err = $@;
84 if (!$request) {
85 $request = eval { $request_class->new(%params) };
86 $new_err ||= $@;
87 }
88 if (!$request) {
89 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
90 }
91  
92 my $response_class = 'Google::Cloud::Automl::V1beta1::PredictionService::PredictResponse';
93 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
94 return $self->transport->call({
95 http_method => 'POST',
96 path => '/google.cloud.automl.v1beta1.PredictionService/Predict',
97 request => $request,
98 response_class => $response_class,
99 });
100 }
101  
102 my $response = $self->transport->call({
103 service => 'google.cloud.automl.v1beta1.PredictionService',
104 method => 'Predict',
105 request => $request,
106 response_class => $response_class,
107 });
108  
109 return $response;
110 }
111 1; # End of Google::Cloud::Automl::V1beta1::PredictionServiceClient
112  
113 __END__
« V1beta1/AutoMlClient.pm ↑ Summary