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.0042'; # TRIAL
3 2     2   1108 use strict;
  2         8  
  2         61  
4 2     2   22 use warnings;
  2         9  
  2         50  
5              
6 2     2   12 use HTTP::Tiny;
  2         4  
  2         34  
7 2     2   9 use Moo;
  2         4  
  2         11  
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 2259 my $self = shift;
15 2         12 my $api_url = $self->api_url;
16 2         5 my $response = undef;
17              
18 2 50       15 if ( HTTP::Tiny->can_ssl() ) {
19 2         49375 $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("true");
25             }
26              
27 2         13 $response = HTTP::Tiny->new->get( $self->api_url );
28              
29 2 50       592767 if ( $response->{success} ) {
30 2         846 $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;