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

filter: Statementstmt 85.7% 36 / 42 Branchbran 25.0% 3 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 75.4% 46 / 61 CC 7 SCAR 11.4
CC
7
Cov
72%
_post_data_api
5.0
_post_data
3.5
new
2.0
CRAP 3.1
« blib/lib/Test/Smoke/App/ConfigSmoke/SmokeDB.pm ↑ Summary blib/lib/Test/Smoke/Syncer/FTP.pm »
1 package Test::Smoke::Poster::LWP_UserAgent;
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '0.002';
6  
7 5 ▶use base 'Test::Smoke::Poster::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Test::Smoke::Poster::LWP_UserAgent - Poster subclass using LWP::UserAgent.
12  
13 =head1 DESCRIPTION
14  
15 This is a subclass of L<Test::Smoke::Poster::Base>.
16  
17 =head2 Test::Smoke::Poster::LWP_UserAgent->new(%arguments)
18  
19 =head3 Extra Arguments
20  
21 =over
22  
23 =item ua_timeout => a timeout te feed to L<LWP::UserAgent>.
24  
25 =back
26  
27 =cut
28  
29 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
30 2 my $class = shift;
31 2 my $self = $class->SUPER::new(@_);
32  
33 2 require LWP::UserAgent;
34 2 my %extra_args;
35 2 ▶ if (defined $self->ua_timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->ua_timeout) 0 2 2
36 0 $extra_args{timeout} = $self->ua_timeout;
37 }
38 2 $self->{_ua} = LWP::UserAgent->new(
39 agent => $self->agent_string(),
40 %extra_args
41 );
42  
43 2 return $self;
44 }
45  
46 =head2 $poster->_post_data()
47  
48 Post the json to CoreSmokeDB using LWP::UserAgent.
49  
50 =cut
51  
52 1 ▶sub _post_data {
Subroutine _post_data: called CC=3 SCAR=12.6
53 1 my $self = shift;
54  
55 1 $self->log_info("Posting to %s via %s.", $self->smokedb_url, $self->poster);
56 1 $self->log_debug("Report data: %s", my $json = $self->get_json);
57  
58 1 my $response = $self->ua->post(
59 $self->smokedb_url,
60 { json => $json }
61 );
62 1 ▶ if ( !$response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 1 1
63 0 $self->log_warn("POST failed: %s", $response->status_line);
64 0 ▶ die sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$response->content ? : 0 0 0
65 "POST to '%s' failed: %s%s\n",
66 $self->smokedb_url,
67 $response->status_line,
68 ($response->content ? sprintf(" (%s)", $response->content) : ""),
69 );
70 }
71  
72 1 $self->log_debug("[CoreSmokeDB] %s", $response->content);
73  
74 1 return $response->content;
75 }
76  
77 =head2 $poster->_post_data_api()
78  
79 This uses the (newish) API function to post the data.
80  
81 =cut
82  
83 1 ▶sub _post_data_api {
Subroutine _post_data_api: called CC=4 SCAR=16.1
84 1 my $self = shift;
85  
86 1 $self->log_info("Posting to %s via %s.", $self->smokedb_url, $self->poster);
87 1 $self->log_debug("Report data: %s", my $json = $self->get_json);
88  
89 1 my $post_data = sprintf(qq/{"report_data": %s}/, $json);
90  
91 1 require HTTP::Request;
92 1 require HTTP::Headers;
93 1 my $request = HTTP::Request->new(
94 POST => $self->smokedb_url,
95 HTTP::Headers->new('Content-Type', 'application/json'),
96 $post_data,
97 );
98 1 my $response = $self->ua->request($request);
99 1 ▶ if (!$response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 1 1
100 0 $self->log_warn("POST failed: %s", $response->status_line);
101 0 ▶ if (not $self->queue_this_report()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->queue_this_report) 0 0 0
102 0 ▶ die sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$response->content ? : 0 0 0
103 "POST to '%s' failed: %s%s\n",
104 $self->smokedb_url,
105 $response->status_line,
106 ($response->content ? sprintf(" (%s)", $response->content) : ""),
107 );
108 }
109 }
110  
111 1 $self->log_debug("[CoreSmokeDB] %s", $response->content);
112  
113 1 return $response->content;
114 }
115  
116 5 1;
117  
118 =head1 COPYRIGHT
119  
120 (c) 2002-2015, Abe Timmerman <abeltje@cpan.org> All rights reserved.
121  
122 With contributions from Jarkko Hietaniemi, Merijn Brand, Campo
123 Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop,
124 Rich Rauenzahn, David Cantrell.
125  
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself.
128  
129 See:
130  
131 =over 4
132  
133 =item * L<http://www.perl.com/perl/misc/Artistic.html>
134  
135 =item * L<http://www.gnu.org/copyleft/gpl.html>
136  
137 =back
138  
139 This program is distributed in the hope that it will be useful,
140 but WITHOUT ANY WARRANTY; without even the implied warranty of
141 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
142  
143 =cut
« blib/lib/Test/Smoke/App/ConfigSmoke/SmokeDB.pm ↑ Summary blib/lib/Test/Smoke/Syncer/FTP.pm »