V1.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/Volume/Types.pm ↑ Summary V1/BatchServiceClient.pm »
1 package Google::Cloud::Batch::V1;
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::Batch::V1::Volume;
14 use Google::Cloud::Batch::V1::Task;
15 use Google::Cloud::Batch::V1::Job;
16 use Google::Cloud::Batch::V1::Batch;
17  
18 our $VERSION = '0.06';
19  
20 has credentials => ( is => 'ro', required => 0 );
21 has transport => ( is => 'rw' );
22  
23 sub BUILD {
24 my ($self) = @_;
25  
26 my $auth = $self->credentials;
27 if (!defined $auth) {
28 $auth = Google::Auth->default();
29 } elsif (!eval { $auth->can('get_token') }) {
30 croak 'Invalid credentials object: must implement get_token()';
31 }
32 my $token = $auth->get_token();
33  
34 my $target = 'batch.googleapis.com:443';
35 my $t = $self->transport || 'grpc';
36  
37 if (ref($t) && eval { $t->can('call') }) {
38 # Already a transport object
39 } elsif (lc($t) eq 'rest') {
40 my $client = Google::Cloud::REST::Client->new(
41 target => $target,
42 auth_token => $token,
43 );
44 $self->transport($client);
45 } else {
46 my $client = Google::gRPC::Client->new(
47 target => $target,
48 auth_token => $token,
49 );
50 $self->transport($client);
51 }
52 }
53  
54 sub create_job {
55 my ($self, %params) = @_;
56  
57 my $request_class = 'Google::Cloud::Batch::V1::Batch::CreateJobRequest';
58 my $request = eval { $request_class->new(\%params) };
59 my $new_err = $@;
60 if (!$request) {
61 $request = eval { $request_class->new(%params) };
62 $new_err ||= $@;
63 }
64 if (!$request) {
65 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
66 }
67  
68 my $response_class = 'Google::Cloud::Batch::V1::Job::Job';
69 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
70 return $self->transport->call({
71 http_method => 'POST',
72 path => '/google.cloud.batch.v1.BatchService/CreateJob',
73 request => $request,
74 response_class => $response_class,
75 });
76 }
77  
78 my $response = $self->transport->call({
79 service => 'google.cloud.batch.v1.BatchService',
80 method => 'CreateJob',
81 request => $request,
82 response_class => $response_class,
83 });
84  
85 return $response;
86 }
87 1; # End of Google::Cloud::Batch::V1
88  
89 __END__
« V1/Volume/Types.pm ↑ Summary V1/BatchServiceClient.pm »