File Coverage

blib/lib/App/PerlWatcher/Watcher/HTTPSimple.pm
Criterion Covered Total %
statement 40 40 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 11 11 100.0
pod 0 2 0.0
total 55 57 96.4


line stmt bran cond sub pod time code
1             package App::PerlWatcher::Watcher::HTTPSimple;
2             {
3             $App::PerlWatcher::Watcher::HTTPSimple::VERSION = '0.20';
4             }
5             # ABSTRACT: The simple HTTP watcher, where actual http responce body is been processed by closure
6              
7 2     2   1561 use 5.12.0;
  2         6  
  2         70  
8 2     2   23 use strict;
  2         4  
  2         2336  
9 2     2   32 use warnings;
  2         7  
  2         140  
10 2     2   815 use utf8;
  2         11  
  2         20  
11              
12 2     2   514 use App::PerlWatcher::EventItem;
  2         8  
  2         63  
13 2     2   16 use Carp;
  2         5  
  2         250  
14 2     2   23 use Smart::Comments -ENV;
  2         6  
  2         28  
15 2     2   1026 use Moo;
  2         6  
  2         20  
16 2     2   2464 use URI;
  2         7054  
  2         476  
17              
18              
19              
20             has 'url' => ( is => 'ro', required => 1);
21              
22              
23             has 'response_handler' => ( is => 'ro', required => 1);
24              
25              
26             has 'processed_response' => ( is => 'rw');
27              
28             with qw/App::PerlWatcher::Watcher::HTTP/;
29              
30             sub description {
31 2     2 0 11 my $self = shift;
32 2         11 my $desc = "HTTP [" . $self->title . "]";
33 2         995 my $response = $self->processed_response;
34 2   100     14 $desc .= " : " . ( $response // q{} );
35 2         14 return $desc;
36             }
37              
38             sub process_http_response {
39 2     2 0 5 my ($self, $content, $headers) = @_;
40 2         5 my ($result, $success) = (undef, 0);
41              
42 2         6 eval {
43 2         17 $result = $self->response_handler->(local $_ = $content);
44 1         11 $success = 1;
45             };
46 2 100       22 $result = $@ if($@);
47              
48             # $result
49             # $success
50 2         11 $self->processed_response($result);
51 2         18 $self->interpret_result($success, $self->callback);
52             }
53              
54             1;
55              
56             __END__