blib/lib/Test/Smoke/Poster/Base.pm

filter: Statementstmt 91.4% 64 / 70 Branchbran 80.0% 8 / 10 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 88.2% 15 / 17 Podpod 100% 5 / 5 totaltotal 79.4% 93 / 117 CC 9 SCAR 9.4
CC
9
Cov
82%
_post_data
6.0
_post_data_api
6.0
post
4.0
CRAP 2.6
« blib/lib/Test/Smoke/App/ConfigSmoke/Smokedir.pm ↑ Summary lib/Test/Smoke/LogMixin.pm »
1 package Test::Smoke::Poster::Base;
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '0.002';
7  
8 6 ▶use base 'Test::Smoke::ObjectBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Test::Smoke::LogMixin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 require Test::Smoke;
12 6 require Test::Smoke::PostQueue;
13  
14 6 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Test::Smoke::Util::LoadAJSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Test::Smoke::Poster::Base - Base class for the posters to CoreSmokeDB.
20  
21 =head1 DESCRIPTION
22  
23 Provide general methods for the poster subclasses.
24  
25 =head2 Test::Smoke::Poster::Base->new(%arguments);
26  
27 =head3 Arguments
28  
29 Named.
30  
31 =over
32  
33 =item smokedb_url => $some_url
34  
35 =item ddir => $smoke_directory
36  
37 =item jsnfile => $json_file (mktest.jsn)
38  
39 =item v => $verbosity
40  
41 =back
42  
43 =head3 Returns
44  
45 An instance of the class.
46  
47 =head3 Exceptions
48  
49 None.
50  
51 =cut
52  
53 13 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
54 13 my $class = shift;
55 13 my %args = @_;
56 # Convert to "underscore names" for Test::Smoke::ObjecBase.
57 my %fields = map
58 13 +( "_$_" => delete $args{$_})
59 , keys %args;
60 13 return bless \%fields, $class;
61 }
62  
63 =head2 $poster->agent_string()
64  
65 Class and intstance method.
66  
67 =head3 Arguments
68  
69 None.
70  
71 =head3 Returns
72  
73 sprintf "Test::Smoke/%s (%s)", $Test::Smoke::VERSION, $class;
74  
75 =head3 Exceptions
76  
77 None.
78  
79 =cut
80  
81 12 ▶sub agent_string {
Subroutine agent_string: called CC=2 SCAR=8.1
Pod documented
82 12 ▶ my $class = ref($_[0]) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
1200
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
83  
84 12 return "Test::Smoke/$Test::Smoke::VERSION ($class)";
85 }
86  
87 =head2 $poster->get_json()
88  
89 =head3 Arguments
90  
91 None.
92  
93 =head3 Returns
94  
95 The json string that was stored in C<< $ddir/$jsnfile >>.
96  
97 =head3 Exceptions
98  
99 File I/O.
100  
101 =cut
102  
103 13 ▶sub get_json {
Subroutine get_json: called CC=2 SCAR=6.9
Pod documented
104 13 my $self = shift;
105  
106 13 my $json_file = $self->json_filename();
107 13 $self->log_debug("Reading from (%s)", $json_file);
108 13 ▶ open my $fh, '<', $json_file or die "Cannot open($json_file): $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $json_file or die "Cannot open($json_file): $!" 12 1 13
109 12 my $json = do { local $/; <$fh> };
110 12 close $fh;
111  
112 12 return $json;
113 }
114  
115 =head2 $poster->json_filename()
116  
117 Returns the the fully qualified file name of the jsonfile.
118  
119 =cut
120  
121 28 ▶sub json_filename {
Subroutine json_filename: called CC=1 SCAR=0.0
Pod documented
122 28 my $self = shift;
123  
124 28 return catfile($self->ddir, $self->jsnfile);
125 }
126  
127 =head2 $poster->post()
128  
129 Post the JSON report to CoreSmokeDB.
130  
131 =head3 Arguments
132  
133 None.
134  
135 =head3 Returns
136  
137 The id of the CoreSmokeDB report on success.
138  
139 =head3 Exceptions
140  
141 HTTP or Test::Smoke::Gateway-application errors.
142  
143 =cut
144  
145 13 ▶sub post {
Subroutine post: called CC=4 SCAR=13.9
146 13 my $self = shift;
147  
148 13 ▶ my $post_method = $self->smokedb_url =~ m{ /api/ }x
Branch: 1 branch
BranchTrueFalseTotal
$self->smokedb_url =~ m[ /api/ ]x ? : 9 4 13
149 ? '_post_data_api'
150 : '_post_data';
151 13 my $response = eval { $self->$post_method() };
152 13 ▶ confess("[POST]: >$@<") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 12 13
153  
154 12 my $response_body;
155 12 eval { $response_body = JSON->new->utf8->allow_nonref->decode($response); 1 };
156 12 ▶ confess("[decode_json] >$response< " . $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
157  
158 12 $self->_process_post_result($response_body);
159 }
160  
161 =head2 $poster->queue_this_report()
162  
163 Use the new queue mechanism to try to send this report before the next smoke
164 run.
165  
166 =cut
167  
168 1 ▶sub queue_this_report {
Subroutine queue_this_report: called CC=1 SCAR=0.0
Pod documented
169 1 my $self = shift;
170  
171 6 ▶ use Test::Smoke::Util qw< get_patch >;
Subroutine BEGIN: called CC=1 SCAR=0.0
172 1 my $patch = get_patch($self->ddir)->[0];
173 1 my $queue = Test::Smoke::PostQueue->new(qfile => $self->qfile);
174 1 return $queue->add($patch);
175 }
176  
177 =head2 $poster->_post_data()
178  
179 Abstract method that should be implemented by the subclass.
180  
181 =head3 Arguments
182  
183 None.
184  
185 =head3 Returns
186  
187 The body of the response.
188  
189 =cut
190  
191 0 ▶sub _post_data {
Subroutine _post_data: not called CC=2 SCAR=17.9
192 0 ▶ my $class = ref($_[0]) || $_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
193 0 croak("Must be implemented by '$class'");
194 }
195  
196 =head2 $poster->_post_data_api()
197  
198 Abstract method that should be implemented by the subclass.
199  
200 =head3 Arguments
201  
202 None.
203  
204 =head3 Returns
205  
206 The body of the response.
207  
208 =cut
209  
210 0 ▶sub _post_data_api {
Subroutine _post_data_api: not called CC=2 SCAR=17.9
211 0 ▶ my $class = ref($_[0]) || $_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
212 0 croak("Must be implemented by '$class'");
213 }
214  
215 =head2 $poster->_process_post_result($response_body)
216  
217 Process the result of the POST action to CoreSmokeDB.
218  
219 =head3 Arguments
220  
221 Positional.
222  
223 =over
224  
225 =item $response_body (the raw JSON string send by CoreSmokeDB)
226  
227 =back
228  
229 =head3 Returns
230  
231 The id of the report on success, I<undef> on failure.
232  
233 =cut
234  
235 12 ▶sub _process_post_result {
Subroutine _process_post_result: called CC=2 SCAR=7.9
236 12 my $self = shift;
237 12 my ($body) = @_;
238  
239 12 ▶ if (exists $body->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $body->{"error"}) 0 12 12
240 0 $self->log_info("CoreSmokeDB: %s", $body->{error});
241 0 return;
242 }
243 12 return $body->{id};
244 }
245  
246 6 1;
247  
248 =head1 COPYRIGHT
249  
250 (c) 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved.
251  
252 With contributions from Jarkko Hietaniemi, Merijn Brand, Campo
253 Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop,
254 Rich Rauenzahn, David Cantrell.
255  
256 This library is free software; you can redistribute it and/or modify
257 it under the same terms as Perl itself.
258  
259 See:
260  
261 =over 4
262  
263 =item * L<http://www.perl.com/perl/misc/Artistic.html>
264  
265 =item * L<http://www.gnu.org/copyleft/gpl.html>
266  
267 =back
268  
269 This program is distributed in the hope that it will be useful,
270 but WITHOUT ANY WARRANTY; without even the implied warranty of
271 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
272  
273 =cut
« blib/lib/Test/Smoke/App/ConfigSmoke/Smokedir.pm ↑ Summary lib/Test/Smoke/LogMixin.pm »