| 1 | package Test::Smoke::Poster::Curl; | ||||||||||||||
| 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 | 5 | ▶ | use File::Temp qw(tempfile); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 5 | ▶ | use URI::Escape qw(uri_escape); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 5 | ▶ | use Test::Smoke::Util::Execute; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | =head1 NAME | ||||||||||||||
| 15 | |||||||||||||||
| 16 | Test::Smoke::Poster::Curl - Poster subclass using curl. | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||
| 19 | |||||||||||||||
| 20 | This is a subclass of L<Test::Smoke::Poster::Base>. | ||||||||||||||
| 21 | |||||||||||||||
| 22 | =head2 Test::Smoke::Poster::Curl->new(%arguments) | ||||||||||||||
| 23 | |||||||||||||||
| 24 | =head3 Extra Arguments | ||||||||||||||
| 25 | |||||||||||||||
| 26 | =over | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =item curlbin => $fq_path_to_curl | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =back | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =cut | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 35 | 2 | my $class = shift; | |||||||||||||
| 36 | 2 | my $self = $class->SUPER::new(@_); | |||||||||||||
| 37 | |||||||||||||||
| 38 | 2 | ▶ | $self->{_curl} = Test::Smoke::Util::Execute->new( | ||||||||||||
|
Condition50%1/2
$self->curlbin || 'curl'
MC/DC0%0/1
$self->curlbin || 'curl'
$self->curlbin
Truth table50%1/2
A
A= $self->curlbin
| |||||||||||||||
| 39 | command => ($self->curlbin || 'curl'), | ||||||||||||||
| 40 | verbose => $self->v | ||||||||||||||
| 41 | ); | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 2 | return $self; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | =head2 $poster->_post_data() | ||||||||||||||
| 47 | |||||||||||||||
| 48 | Post the json to CoreSmokeDB using L<curl(1)>. | ||||||||||||||
| 49 | |||||||||||||||
| 50 | =cut | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 1 | ▶ | sub _post_data { | ||||||||||||
|
Subroutine
_post_data: called CC=6 SCAR=19.2
| |||||||||||||||
| 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 $form_data = sprintf("json=%s", uri_escape($json)); | |||||||||||||
| 59 | 1 | my ($fh, $filename) = tempfile('curl-tsrepostXXXXXX', TMPDIR => 1); | |||||||||||||
| 60 | 1 | print $fh $form_data; | |||||||||||||
| 61 | 1 | close($fh); | |||||||||||||
| 62 | |||||||||||||||
| 63 | my $response = $self->curl->run( | ||||||||||||||
| 64 | '-A' => $self->agent_string(), | ||||||||||||||
| 65 | '-d' => "\@$filename", | ||||||||||||||
| 66 | ($self->ua_timeout ? ('--max-time' => $self->ua_timeout) : ()), | ||||||||||||||
| 67 | ($self->curl->verbose ? () : '--silent'), | ||||||||||||||
| 68 | 1 | ▶ | @{ $self->curlargs }, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 69 | $self->smokedb_url, | ||||||||||||||
| 70 | ); | ||||||||||||||
| 71 | 1 | ▶ | 1 while unlink($filename); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | ▶ | if ($self->curl->exitcode) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | ▶ | $self->log_warn("[POST] curl exitcode: %d %s", $self->curl->exitcode, $response || ''); | ||||||||||||
|
Condition0%0/2
$response || ''
MC/DC0%0/1
$response || ''
$response
Truth table0%0/2
A
A= $response
| |||||||||||||||
| 75 | 0 | die sprintf( | |||||||||||||
| 76 | "POST to '%s' curl failed: %d\n", | ||||||||||||||
| 77 | $self->smokedb_url, | ||||||||||||||
| 78 | $self->curl->exitcode | ||||||||||||||
| 79 | ); | ||||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 1 | $self->log_debug("[CoreSmokeDB] %s", $response); | |||||||||||||
| 83 | |||||||||||||||
| 84 | 1 | return $response; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | |||||||||||||||
| 87 | =head2 $poster->_post_data_api() | ||||||||||||||
| 88 | |||||||||||||||
| 89 | Post the json to CoreSmokeDB API-function using L<curl(1)>. | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =cut | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 1 | ▶ | sub _post_data_api { | ||||||||||||
|
Subroutine
_post_data_api: called CC=7 SCAR=22.0
| |||||||||||||||
| 94 | 1 | my $self = shift; | |||||||||||||
| 95 | |||||||||||||||
| 96 | 1 | $self->log_info("Posting to %s via %s.", $self->smokedb_url, $self->poster); | |||||||||||||
| 97 | 1 | $self->log_debug("Report data: %s", my $json = $self->get_json); | |||||||||||||
| 98 | |||||||||||||||
| 99 | 1 | my $post_data = sprintf(qq/{"report_data": %s}/, $json); | |||||||||||||
| 100 | 1 | my ($fh, $filename) = tempfile('curl-tsrepostXXXXXX', TMPDIR => 1); | |||||||||||||
| 101 | 1 | print {$fh} $post_data; | |||||||||||||
| 102 | 1 | close($fh); | |||||||||||||
| 103 | |||||||||||||||
| 104 | my $response = $self->curl->run( | ||||||||||||||
| 105 | '-H' => 'Content-Type: application/json', | ||||||||||||||
| 106 | '-A' => $self->agent_string(), | ||||||||||||||
| 107 | '-d' => "\@$filename", | ||||||||||||||
| 108 | ($self->ua_timeout ? ('--max-time' => $self->ua_timeout) : ()), | ||||||||||||||
| 109 | ($self->curl->verbose ? () : '--silent'), | ||||||||||||||
| 110 | 1 | ▶ | @{ $self->curlargs }, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 111 | $self->smokedb_url, | ||||||||||||||
| 112 | ); | ||||||||||||||
| 113 | 1 | ▶ | 1 while unlink($filename); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 114 | |||||||||||||||
| 115 | 1 | ▶ | if ($self->curl->exitcode) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | 0 | ▶ | $self->log_warn( | ||||||||||||
|
Condition0%0/2
$response || ''
MC/DC0%0/1
$response || ''
$response
Truth table0%0/2
A
A= $response
| |||||||||||||||
| 117 | "[POST] curl exitcode: %d %s", | ||||||||||||||
| 118 | $self->curl->exitcode, $response || '' | ||||||||||||||
| 119 | ); | ||||||||||||||
| 120 | 0 | ▶ | if (not $self->queue_this_report()) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 121 | 0 | die sprintf( | |||||||||||||
| 122 | "POST to '%s' curl failed: %d\n", | ||||||||||||||
| 123 | $self->smokedb_url, | ||||||||||||||
| 124 | $self->curl->exitcode | ||||||||||||||
| 125 | ); | ||||||||||||||
| 126 | } | ||||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | 1 | $self->log_debug("[CoreSmokeDB] %s", $response); | |||||||||||||
| 130 | |||||||||||||||
| 131 | 1 | return $response; | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | |||||||||||||||
| 134 | 5 | 1; | |||||||||||||
| 135 | |||||||||||||||
| 136 | =head1 COPYRIGHT | ||||||||||||||
| 137 | |||||||||||||||
| 138 | (c) 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved. | ||||||||||||||
| 139 | |||||||||||||||
| 140 | With contributions from Jarkko Hietaniemi, Merijn Brand, Campo | ||||||||||||||
| 141 | Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop, | ||||||||||||||
| 142 | Rich Rauenzahn, David Cantrell. | ||||||||||||||
| 143 | |||||||||||||||
| 144 | This library is free software; you can redistribute it and/or modify | ||||||||||||||
| 145 | it under the same terms as Perl itself. | ||||||||||||||
| 146 | |||||||||||||||
| 147 | See: | ||||||||||||||
| 148 | |||||||||||||||
| 149 | =over 4 | ||||||||||||||
| 150 | |||||||||||||||
| 151 | =item * L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =item * L<http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||
| 154 | |||||||||||||||
| 155 | =back | ||||||||||||||
| 156 | |||||||||||||||
| 157 | This program is distributed in the hope that it will be useful, | ||||||||||||||
| 158 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||
| 159 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||
| 160 | |||||||||||||||
| 161 | =cut | ||||||||||||||