File Coverage

blib/lib/Locale/Country/OFAC.pm
Criterion Covered Total %
statement 36 36 100.0
branch 11 12 91.6
condition 11 17 64.7
subroutine 8 8 100.0
pod 3 3 100.0
total 69 76 90.7


line stmt bran cond sub pod time code
1             package Locale::Country::OFAC;
2              
3 3     3   165636 use strict;
  3         39  
  3         65  
4 3     3   11 use warnings;
  3         12  
  3         57  
5              
6 3     3   10 use Exporter;
  3         4  
  3         107  
7 3     3   13 use Carp;
  3         6  
  3         138  
8              
9 3     3   1239 use Readonly;
  3         9307  
  3         3719  
10             Readonly my @CRIMEA_REGION => (95000..99999, 295000..299999 );
11              
12             our @ISA = qw(Exporter);
13             our @EXPORT_OK = qw( get_sanction_by_code is_region_sanctioned is_division_sanctioned );
14              
15             our $VERSION = '1.3.0'; # VERSION
16             # ABSTRACT: Module to look up OFAC Sanctioned Countries
17              
18             =pod
19              
20             =encoding utf8
21              
22             =head1 NAME
23              
24             Locale::Country::OFAC - Module to look up OFAC Sanctioned Countries
25              
26             =head1 SYNOPSIS
27              
28             use strict;
29             use warnings;
30             use Locale::Country::OFAC qw( get_sanction_by_code is_region_sanctioned is_division_sanctioned );
31              
32             my $is_sanctioned = get_sanction_by_code( 'IR' ); # Country Code
33             my $is_sanctioned = is_region_sanctioned( 'UK', 95000 ); # Country Code, Zip Code
34             my $is_sanctioned = is_division_sanctioned( 'UK', '43' ); # Country Code, SubCountry/Division Code
35              
36             =head1 DESCRIPTION
37              
38             Module to lookup if a country is OFAC Sanctioned.
39              
40             OFAC Source: <>
41              
42             =head1 METHODS
43              
44             =head2 get_sanction_by_code
45              
46             use Locale::Country::OFAC qw( get_sanction_by_code );
47              
48             my $iran = 'IR';
49              
50             if ( get_sanction_by_code($iran) ) {
51             print "Sorry, can't do business- country is Sanctioned\n";
52             }
53              
54             Returns 1 if the country is sanctioned, 0 if not. It also accepts lower case and 3 letter country codes.
55              
56             =head2 is_region_sanctioned
57              
58             use Locale::Country::OFAC qw( is_region_sanctioned );
59              
60             my $russia = 'RU';
61             my $zip = 95001;
62              
63             if ( is_region_sanctioned( $russia, $zip ) ) {
64             print "region is sanctioned \n";
65             }
66              
67             This method takes a country code and zip code. It returns 1 if it is sanctioned and 0 if not.
68              
69             =head3 CAVEATS AND LIMITATIONS
70              
71             Russian and Ukranian country codes are in this module's lookup table,
72             but only certain zip codes of them are currently OFAC sanctioned. This is the reasoning
73             for creating the is_region_sanctioned method.
74              
75             =head2 is_division_sanctioned
76              
77             use Locale::Country::OFAC qw( is_division_sanctioned );
78              
79             my $ukraine = 'UA';
80             my $crimea = '43'; # ISO-3166-2 for Crimera
81              
82             if ( is_division_sanctioned( $ukraine, $crimea ) ) {
83             print "division is sanctioned \n";
84             }
85              
86              
87             This method takes a country and subcountry code. It returnes 1 if the provided combination is sanctioned and 0 if not.
88              
89             =head3 CAVEATS AND LIMITATIONS
90              
91             All of Crimea is considered sanctioned (when searching for ISO-3166-2:UA 43 ).
92              
93             =head1 AUTHOR
94              
95             Daniel Culver, C<< perlsufi@cpan.org >>
96              
97             =head1 THANKS TO
98              
99             Robert Stone, C<< drzigman@cpan.org >>
100              
101             Doug Schrag
102              
103             Eris Caffee
104              
105             HostGator
106              
107             =head1 COPYRIGHT
108              
109             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
110              
111             =cut
112              
113             our %sanctioned_country_codes = (
114             IRN => 1,
115             IR => 1,
116             CUB => 1,
117             CU => 1,
118             PRK => 1,
119             KP => 1,
120             SYR => 1,
121             SY => 1,
122             UA => \@CRIMEA_REGION, # Ukraine Crimea zip code
123             UKR => \@CRIMEA_REGION,
124             RU => \@CRIMEA_REGION, # Russia Crimea zip code
125             RUS => \@CRIMEA_REGION,
126             );
127              
128             our %sanctioned_country_divisions = (
129             UA => [qw( 43 )],
130             UKR => [qw( 43 )],
131             RU => [qw( 43 )], # This actually doesn't exist in Russia per ISO-3166-2, but for ease of use include it
132             RUS => [qw( 43 )], # This actually doesn't exist in Russia per ISO-3166-2, but for ease of use include it
133             );
134              
135             sub get_sanction_by_code {
136 36   33 36 1 8029 my $country_code = shift || croak "get_sanction_by_code requires country code";
137              
138 36         94 my $country_sanction = $sanctioned_country_codes{uc $country_code};
139 36   100     315 return defined $country_sanction && !ref $country_sanction || 0;
140             }
141              
142             sub is_region_sanctioned {
143 36   66 36 1 85461 my $country = shift || croak "is_region_sanctioned requires country code";
144 35   66     110 my $zip = shift || croak "is_region_sanctioned requires zip code";
145              
146 34 100       131 if ( defined $sanctioned_country_codes{uc$country} ) {
147 33         92 my $zipcodes = $sanctioned_country_codes{uc$country};
148 33 100       92 if ( ref $zipcodes eq 'ARRAY' ) {
149 32 100       120 if ( grep { $_ eq $zip } @$zipcodes ) {
  320000         1246769  
150 16         3887 return 1;
151             }
152             }
153             }
154              
155 18         15451 return get_sanction_by_code($country);
156             }
157              
158             sub is_division_sanctioned {
159 12   66 12 1 13725 my $country = shift || croak 'is_division_sanctioned requires country code';
160 11   66     40 my $division = shift || croak 'is_division_sanctioned requires division';
161              
162 10 100       27 if ( defined $sanctioned_country_divisions{ uc $country } ) {
163 8         14 my $divisions = $sanctioned_country_divisions{ uc $country };
164              
165 8 50       18 if ( ref $divisions eq 'ARRAY' ) {
166 8 100       15 if ( grep { $_ eq $division } @$divisions ) {
  8         23  
167 4         14 return 1;
168             }
169             }
170             }
171              
172 6         12 return get_sanction_by_code($country);
173             }
174              
175             1;