blib/lib/BZ/Client/API.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 67 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.9';
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__
70  
71 =pod
72  
73 =encoding UTF-8
74  
75 =head1 NAME
76  
77 BZ::Client::API - Abstract base class for the clients of the Bugzilla API.
78  
79 =head1 VERSION
80  
81 version 4.9
82  
83 =head1 SYNOPSIS
84  
85 This is an abstract base class for classes like L<BZ::Client::Product>, which
86 are subclassing this one, in order to inherit common functionality.
87  
88 None of these methods are useful to end users.
89  
90 =head1 METHODS
91  
92 =head2 api_call
93  
94 Wraps C<BZ::Client::api_call>
95  
96 =head2 error
97  
98 Wraps C<BZ::Client::error>
99  
100 =head2 new
101  
102 Generic C<new()> function. Saving doing it over and over.
103  
104 =head2 _create
105  
106 Calls something on the Bugzilla Server, and returns and ID.
107  
108 =head2 _returns_array
109  
110 Calls something on the Bugzilla Server, and returns an array / arrayref.
111  
112 =head1 SEE ALSO
113  
114 L<BZ::Client>
115  
116 =head1 AUTHORS
117  
118 =over 4
119  
120 =item *
121  
122 Dean Hamstead <dean@bytefoundry.com.au>
123  
124 =item *
125  
126 Jochen Wiedmann <jochen.wiedmann@gmail.com>
127  
128 =back
129  
130 =head1 COPYRIGHT AND LICENSE
131  
132 This software is copyright (c) 2026 by Dean Hamstad.
133  
134 This is free software; you can redistribute it and/or modify it under
135 the same terms as the Perl 5 programming language system itself.
136  
137 =cut