Client/API.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 71 CC 5 SCAR 17.6
CC
5
Cov
0%
_returns_array
12.0
_create
6.0
_accessor
6.0
CRAP 5.8
1 #!/bin/false
2 # PODNAME: BZ::Client::API
3 # ABSTRACT: Abstract base class for the clients of the Bugzilla API.
4  
5 use strict;
6 use warnings 'all';
7  
8 package BZ::Client::API;
9 $BZ::Client::API::VERSION = '4.91';
10  
11 sub api_call {
12 my(undef, $client, $methodName, $params, $options) = @_;
13 return $client->api_call($methodName, $params, $options)
14 }
15  
16 sub error {
17 my(undef, $client, $message, $http_code, $xmlrpc_code) = @_;
18 return $client->error($message, $http_code, $xmlrpc_code)
19 }
20  
21 sub new {
22 my $class = shift;
23 my $self = { @_ };
24 bless($self, ref($class) || $class);
25 return $self
26 }
27  
28 # Move stuff here so we dont do it over and over
29  
30 sub _create {
31 my(undef, $client, $methodName, $params, $key) = @_;
32 $key ||= 'id';
33 my $sub = ( caller(1) )[3];
34 $client->log('debug', $sub . ': Running');
35 my $result = __PACKAGE__->api_call($client, $methodName, $params);
36 my $id = $result->{$key};
37 __PACKAGE__->error($client, "Invalid reply by server, expected $methodName $key.")
38 unless $id;
39 $client->log('debug', "$sub: Returned $id");
40 return $id
41 }
42  
43 sub _returns_array {
44 my(undef, $client, $methodName, $params, $key) = @_;
45 my $sub = ( caller(1) )[3];
46 $client->log('debug',$sub . ': Running');
47 my $result = __PACKAGE__->api_call($client, $methodName, $params);
48 my $items = $result->{$key};
49 __PACKAGE__->error($client, "Invalid reply by server, expected array of $methodName details")
50 unless ($items and 'ARRAY' eq ref $items);
51 $client->log('debug', "$sub: Received results");
52 return wantarray ? @$items : $items
53 }
54  
55  
56  
57 1;
58  
59 # Simple accessor helper for subclasses
60 sub _accessor {
61 my ($self, $field) = (shift, shift);
62 if (@_) {
63 $self->{$field} = shift;
64 } else {
65 return $self->{$field};
66 }
67 }
68  
69 __END__