File Coverage

blib/lib/WebService/CIA.pm
Criterion Covered Total %
statement 38 38 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 5 5 100.0
total 54 56 96.4


line stmt bran cond sub pod time code
1             package WebService::CIA;
2              
3             require 5.005_62;
4 4     4   32776 use strict;
  4         8  
  4         158  
5 4     4   22 use warnings;
  4         6  
  4         116  
6 4     4   22 use Carp;
  4         12  
  4         1885  
7              
8             our $VERSION = '1.4';
9              
10             $WebService::CIA::base_url = "https://www.cia.gov/library/publications/the-world-factbook/";
11              
12             sub new {
13              
14 2     2 1 23 my $proto = shift;
15 2         5 my $opts = shift;
16 2   33     15 my $class = ref($proto) || $proto;
17 2         5 my $self = {};
18              
19 2 100       11 unless (exists $opts->{Source}) {
20 1         223 croak("WebService::CIA: No source object specified");
21             }
22 1         4 $self->{SOURCE} = $opts->{Source};
23              
24 1         3 bless ($self, $class);
25 1         4 return $self;
26              
27             }
28              
29             sub get {
30              
31 2     2 1 6 my $self = shift;
32 2         5 my ($cc, $f) = @_;
33 2         5 my $value = $self->source->value($cc, $f);
34 2         8 return $value;
35              
36             }
37              
38             sub get_all_hashref {
39              
40 3     3 1 7 my $self = shift;
41 3         4 my $country = shift;
42 3         4 my $data = {};
43 3         7 foreach my $cc (@$country) {
44 3         7 $data->{$cc} = $self->source->all($cc);
45             }
46 3         14 return $data;
47              
48             }
49              
50             sub get_hashref {
51              
52 2     2 1 232 my $self = shift;
53 2         3 my ($country, $field) = @_;
54 2         3 my $data = {};
55 2         4 foreach my $cc (@$country) {
56 3         5 $data->{$cc} = {};
57 3         5 foreach my $f (@$field) {
58 4         9 $data->{$cc}->{$f} = $self->source->value($cc, $f);
59             }
60             }
61 2         4 return $data;
62              
63             }
64              
65             sub source {
66              
67 10     10 1 584 my $self = shift;
68 10         40 return $self->{SOURCE};
69              
70             }
71              
72             1;
73              
74             __END__