File Coverage

blib/lib/Locale/Country/OFAC.pm
Criterion Covered Total %
statement 30 30 100.0
branch 5 6 83.3
condition 7 11 63.6
subroutine 9 9 100.0
pod 2 2 100.0
total 53 58 91.3


line stmt bran cond sub pod time code
1             package Locale::Country::OFAC;
2              
3 1     1   64330 use strict;
  1         2  
  1         35  
4 1     1   4 use warnings;
  1         1  
  1         25  
5              
6 1     1   3 use Exporter;
  1         1  
  1         25  
7 1     1   4 use Carp;
  1         1  
  1         57  
8              
9 1     1   4 use List::Util qw(any);
  1         1  
  1         82  
10 1     1   524 use Readonly;
  1         2256  
  1         1196  
11              
12             Readonly my @CRIMEA_REGION => (95000..99999, 295000..299999 );
13              
14             our @ISA = qw(Exporter);
15             our @EXPORT_OK = qw( get_sanction_by_code is_region_sanctioned );
16              
17             our $VERSION = '1.1.0'; # VERSION 1.1.0
18             # ABSTRACT: Module to look up OFAC Sanctioned Countries
19              
20             =pod
21              
22             =encoding utf8
23              
24             =head1 NAME
25              
26             Locale::Country::OFAC - Module to look up OFAC Sanctioned Countries
27              
28             =head1 SYNOPSIS
29              
30             use strict;
31             use warnings;
32             use Locale::Country::OFAC qw( get_sanction_by_code );
33              
34             my $sanction = get_sanction_by_code('IR');
35              
36             =head1 DESCRIPTION
37              
38             Module to lookup if a country is OFAC Sanctioned.
39             Takes a country code and returns a true value if it is.
40              
41             OFAC Source: <>
42              
43             =head1 METHODS
44              
45             =head2 get_sanction_by_code
46              
47             my $iran = 'IR';
48              
49             if ( get_sanction_by_code($iran) ) {
50             print "Sorry, can't do business- country is Sanctioned\n";
51             }
52              
53             Returns 1 if the country is sanctioned, 0 if not. It also accepts lower case and 3 letter country codes.
54              
55             =head2 is_region_sanctioned
56              
57             use Locale::Country::OFAC qw( is_region_sanctioned );
58              
59             my $russia = 'RU';
60             my $zip = 95001;
61              
62             if ( is_region_sanctioned( $russia, $zip ) ) {
63             print "region is sanctioned \n";
64             }
65              
66             This method takes a country code and zip code. It returns 1 if it is sanctioned and 0 if not.
67              
68             =head1 CAVEATS AND LIMITATIONS
69              
70             Russian and Ukranian country codes are in this module's lookup table,
71             but only certain zip codes of them are currently OFAC sanctioned. This is the reasoning
72             for creating the is_region_sanctioned method.
73              
74             =head1 AUTHOR
75              
76             Daniel Culver, C<< perlsufi@cpan.org >>
77              
78             =head1 THANKS TO
79              
80             Robert Stone, C<< drzigman@cpan.org >>
81              
82             Doug Schrag
83              
84             Eris Caffee
85              
86             HostGator
87              
88             PerlMonks, L<< http://www.perlmonks.com >>
89              
90             =head1 COPYRIGHT
91              
92             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
93              
94             =cut
95              
96              
97             our %sanctioned_country_codes = (
98             IRN => 1,
99             IR => 1,
100             CUB => 1,
101             CU => 1,
102             SDN => 1,
103             SD => 1,
104             PRK => 1,
105             KP => 1,
106             SYR => 1,
107             SY => 1,
108             UA => \@CRIMEA_REGION, # Ukraine Crimea zip code
109             UKR => \@CRIMEA_REGION,
110             RU => \@CRIMEA_REGION, # Russia Crimea zip code
111             RUS => \@CRIMEA_REGION,
112             );
113              
114             sub get_sanction_by_code {
115 18   33 18 1 522 my $country_code = shift || croak "get_sanction_by_code requires country code";
116              
117 18         47 my $country_sanction = $sanctioned_country_codes{uc $country_code};
118 18   100     191 return defined $country_sanction && !ref $country_sanction || 0;
119             }
120              
121             sub is_region_sanctioned {
122 15   66 15 1 173 my $country = shift || croak "is_region_sanctioned requires country code";
123 14   66     53 my $zip = shift || croak "is_region_sanctioned requires zip code";
124              
125 13 100       60 if ( defined $sanctioned_country_codes{uc$country} ) {
126 12         23 my $value = $sanctioned_country_codes{uc$country};
127 12 50       38 if ( ref $value eq 'ARRAY' ) {
128 12 100   69304   115 if ( any { $_ == $zip } @$value ) {
  69304         258022  
129 8         128 return 1;
130             }
131             }
132             }
133 5         4748 return get_sanction_by_code($country);
134             }
135              
136             1;