File Coverage

blib/lib/Test/Smoke/Poster/Curl.pm
Criterion Covered Total %
statement 18 37 48.6
branch 0 6 0.0
condition 0 4 0.0
subroutine 6 8 75.0
pod 1 1 100.0
total 25 56 44.6


line stmt bran cond sub pod time code
1             package Test::Smoke::Poster::Curl;
2 4     4   31 use warnings;
  4         8  
  4         128  
3 4     4   21 use strict;
  4         8  
  4         148  
4              
5             our $VERSION = '0.001';
6              
7 4     4   22 use base 'Test::Smoke::Poster::Base';
  4         7  
  4         1887  
8              
9 4     4   31 use File::Temp qw(tempfile);
  4         11  
  4         181  
10 4     4   1462 use URI::Escape qw(uri_escape);
  4         5570  
  4         216  
11              
12 4     4   1262 use Test::Smoke::Util::Execute;
  4         9  
  4         1294  
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.
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             sub new {
35 0     0 1   my $class = shift;
36 0           my $self = $class->SUPER::new(@_);
37              
38 0   0       $self->{_curl} = Test::Smoke::Util::Execute->new(
39             command => ($self->curlbin || 'curl'),
40             verbose => $self->v
41             );
42              
43 0           return $self;
44             }
45              
46             =head2 $poster->_post_data()
47              
48             Post the json to CoreSmokeDB using L.
49              
50             =cut
51              
52             sub _post_data {
53 0     0     my $self = shift;
54              
55 0           $self->log_info("Posting to %s via %s.", $self->smokedb_url, $self->poster);
56 0           $self->log_debug("Report data: %s", my $json = $self->get_json);
57              
58 0           my $form_data = sprintf("json=%s", uri_escape($json));
59 0           my ($fh, $filename) = tempfile('curl-tsrepostXXXXXX', TMPDIR => 1);
60 0           print $fh $form_data;
61 0           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 0 0         @{ $self->curlargs },
  0 0          
69             $self->smokedb_url,
70             );
71 0           1 while unlink($filename);
72              
73 0 0         if ($self->curl->exitcode) {
74 0   0       $self->log_warn("[POST] curl exitcode: %d %s", $self->curl->exitcode, $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 0           $self->log_debug("[CoreSmokeDB] %s", $response);
83              
84 0           return $response;
85             }
86              
87             1;
88              
89             =head1 COPYRIGHT
90              
91             (c) 2002-2013, Abe Timmerman All rights reserved.
92              
93             With contributions from Jarkko Hietaniemi, Merijn Brand, Campo
94             Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop,
95             Rich Rauenzahn, David Cantrell.
96              
97             This library is free software; you can redistribute it and/or modify
98             it under the same terms as Perl itself.
99              
100             See:
101              
102             =over 4
103              
104             =item * L
105              
106             =item * L
107              
108             =back
109              
110             This program is distributed in the hope that it will be useful,
111             but WITHOUT ANY WARRANTY; without even the implied warranty of
112             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
113              
114             =cut