File Coverage

blib/lib/WebService/Lobid.pm
Criterion Covered Total %
statement 20 25 80.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 35 77.1


line stmt bran cond sub pod time code
1             package WebService::Lobid;
2             $WebService::Lobid::VERSION = '0.00421';
3 2     2   861 use strict;
  2         4  
  2         50  
4 2     2   15 use warnings;
  2         6  
  2         41  
5              
6 2     2   8 use HTTP::Tiny;
  2         4  
  2         38  
7 2     2   9 use Moo;
  2         3  
  2         10  
8              
9             has api_url => ( is => 'rw', default=> 'https://lobid.org/');
10             has api_status => (is => 'rw');
11             has use_ssl => ( is => 'rw' );
12              
13             sub BUILD {
14 2     2 0 1945 my $self = shift;
15 2         10 my $api_url = $self->api_url;
16 2         5 my $response = undef;
17              
18 2 50       16 if ( HTTP::Tiny->can_ssl() ) {
19 2         41649 $self->use_ssl("true");
20             }
21             else {
22 0         0 $api_url =~ s/https/http/;
23 0         0 $self->api_url($api_url);
24 0         0 $self->use_ssl("false");
25             }
26              
27 2         12 $response = HTTP::Tiny->new->get( $self->api_url );
28              
29 2 50       483405 if ( $response->{success} ) {
30 2         875 $self->api_status("ok");
31             }
32             else {
33 0           $self->api_status("error");
34             warn sprintf( "API URL %s is not reachable: %s (%s)",
35             $self->api_url, $response->{reason},
36 0           $response->{status} );
37             }
38             } ## end sub BUILD
39              
40             1;