| 1 | package WebService::CIA; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | require 5.005_62; | |||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | our $VERSION = '1.4'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | $WebService::CIA::base_url = "https://www.cia.gov/library/publications/the-world-factbook/"; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | my $proto = shift; | |||||||||||||||||||
| 15 | 2 | my $opts = shift; | |||||||||||||||||||
| 16 | 2 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 17 | 2 | my $self = {}; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | ▶ | unless (exists $opts->{Source}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 1 | croak("WebService::CIA: No source object specified"); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | 1 | $self->{SOURCE} = $opts->{Source}; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | bless ($self, $class); | |||||||||||||||||||
| 25 | 1 | return $self; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 2 | my $self = shift; | |||||||||||||||||||
| 32 | 2 | my ($cc, $f) = @_; | |||||||||||||||||||
| 33 | 2 | my $value = $self->source->value($cc, $f); | |||||||||||||||||||
| 34 | 2 | return $value; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 3 | ▶ | sub get_all_hashref { | ||||||||||||||||||
|
Subroutine
get_all_hashref: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | my $self = shift; | |||||||||||||||||||
| 41 | 3 | my $country = shift; | |||||||||||||||||||
| 42 | 3 | my $data = {}; | |||||||||||||||||||
| 43 | 3 | foreach my $cc (@$country) { | |||||||||||||||||||
| 44 | 3 | $data->{$cc} = $self->source->all($cc); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 3 | return $data; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | ▶ | sub get_hashref { | ||||||||||||||||||
|
Subroutine
get_hashref: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 2 | my $self = shift; | |||||||||||||||||||
| 53 | 2 | my ($country, $field) = @_; | |||||||||||||||||||
| 54 | 2 | my $data = {}; | |||||||||||||||||||
| 55 | 2 | foreach my $cc (@$country) { | |||||||||||||||||||
| 56 | 3 | $data->{$cc} = {}; | |||||||||||||||||||
| 57 | 3 | foreach my $f (@$field) { | |||||||||||||||||||
| 58 | 4 | $data->{$cc}->{$f} = $self->source->value($cc, $f); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | 2 | return $data; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 10 | ▶ | sub source { | ||||||||||||||||||
|
Subroutine
source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 10 | my $self = shift; | |||||||||||||||||||
| 68 | 10 | return $self->{SOURCE}; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||