OFAC.pm

filter: Statementstmt 59.0% 36 / 61 Branchbran 50.0% 6 / 12 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 54.5% 6 / 11 Podpod 100% 7 / 7 totaltotal 54.7% 58 / 106 CC 12 SCAR 18.4
CC
12
Cov
55%
new
11.1
checkString
6.0
willUpdate
6.0
CRAP 6.3
« OFAC/SDN.pm ↑ Summary OFAC/SDN/Schema.pm »
1 package Data::OFAC;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Data::OFAC::SDN;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Data::OFAC - A Perl interface to the United States Office of Foreign Assets
11 Control (OFAC) Specially Designated Nationals List (SDN)
12  
13 =head1 VERSION
14  
15 Version 0.80
16  
17 =cut
18  
19 4 our $VERSION = '0.80';
20  
21 =head1 DESCRIPTION
22  
23 From OFAC's Website:
24 As part of its enforcement efforts, OFAC publishes a list of
25 individuals and companies owned or controlled by, or acting for or on
26 behalf of, targeted countries. It also lists individuals, groups, and
27 entities, such as terrorists and narcotics traffickers designated under
28 programs that are not country-specific. Collectively, such individuals
29 and companies are called "Specially Designated Nationals" or "SDNs."
30 Their assets are blocked and U.S. persons are generally prohibited from
31 dealing with them.
32  
33 This interface is helpful for insitutions that use Perl, and may have a
34 need to screen individuals as potential customers.
35  
36 Note that this module will require occasional internet access if
37 auto_update is enabled. Auto update contacts OFAC's website to download
38 the latest SDN list in "CSV" format. These files are used to build a SQLite
39 database. In order to remain "compliant" reasonably frequent updates are
40 recommended. For financial institutions, not complying with this carries
41 heavy penalties. I am not a lawyer, and I cannot recommend your update
42 frequency. I've set 12 hours as I believe this to be a reasonable update
43 interval. Again, this module carries no waranty, and cannot be a full
44 replacement for full compliance with the regulations. YMMV.
45  
46 =head1 SYNOPSIS
47  
48 A simple example.
49  
50 use Data::OFAC;
51  
52 my $ofac = Data::OFAC->new(
53 auto_update => 1,
54 auto_update_frequency => 12,
55 database_file => '/path/to/sdn.sqlite'
56 );
57  
58 my $result = $ofac->checkString($string);
59  
60 if ( defined $result ) {
61 print "Hit found:" .
62 Dumper $result; # varries by hit, but is just a hash.
63 }
64 ...
65  
66 =head1 SUBROUTINES/METHODS
67  
68 =head2 new
69  
70 Instantiates the base object. Note that the following parameters are
71 currently supported:
72  
73 =head3 auto_update [0,1] (Optional)
74  
75 Tells Data::OFAC whether you desire to update the database. It will check a
76 table in SQLite to determine the last update date/time and decide if
77 checking for a new update is warranted. Note that the download is not
78 particularly large, but the download and subsequent rebuild of the database
79 could introduce a startup penalty that may be undesirable. (30 seconds on my
80 quad core MBP) For long running processes, there is no present method for
81 updating on the fly. Since I run this as part of a larger web service, my
82 processes cycle frequently enough that I never have this problem. YMMV
83  
84 0 - disable
85 1 - enable *default
86  
87 =head3 auto_update_frequency [int] (Optional)
88  
89 Sets the desired delay between rechecks. Data::OFAC will recheck at each
90 start if the auto_update property is set to 1.
91  
92 Default: 12 (hours)
93  
94 =head3 database_file [string] (Optional)
95  
96 Sets the desired location to keep the database file. The default is your
97 home directory in the ".ofac" directory.
98  
99 Default: $ENV{HOME}/.ofac/sdn.sqlite or $ENV{USERPROFILE}\.ofac\sdn.sqlite
100  
101 =cut
102  
103 3 ▶sub new {
Subroutine new: called CC=9 SCAR=24.1
Pod documented
104 3 my $class = shift;
105 3 my %vars = @_;
106 3 my $self = bless {}, $class;
107  
108 0 map { $self->{$_} = $vars{$_} } keys %vars;
109  
110 3 ▶ unless ( defined $self->{auto_update} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"auto_update"}) 3 0 3
111 3 $self->{auto_update} = 1;
112 }
113  
114 3 ▶ unless ( defined $self->{auto_update_frequency} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"auto_update_frequency"}) 3 0 3
115 3 $self->{auto_update_frequency} = 12;
116 }
117  
118 3 ▶ unless ( defined $self->{use_only_exact} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"use_only_exact"}) 3 0 3
119 3 $self->{use_only_exact} = 0;
120 }
121  
122 3 ▶ unless ( defined $self->{database_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"database_file"}) 3 0 3
123 3 ▶ unless ( -d ( $ENV{HOME} || $ENV{USERPROFILE} ) . "/.ofac" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d ($ENV{"HOME"} || $ENV{"USERPROFILE"}) . '/.ofac') 1 2 3
Condition33%1/3
$ENV{'HOME'} || $ENV{'USERPROFILE'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$ENV{'HOME'} || $ENV{'USERPROFILE'}
$ENV{'HOME'} $ENV{'USERPROFILE'}
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= $ENV{'USERPROFILE'}
ABresult
1X1
011
000
124 1 ▶ mkdir( ( $ENV{HOME} || $ENV{USERPROFILE} ) . "/.ofac" );
Condition33%1/3
$ENV{'HOME'} || $ENV{'USERPROFILE'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'HOME'} || $ENV{'USERPROFILE'}
$ENV{'HOME'} $ENV{'USERPROFILE'}
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= $ENV{'USERPROFILE'}
ABresult
1X1
011
000
125 }
126 $self->{database_file}
127 3 ▶ = ( $ENV{HOME} || $ENV{USERPROFILE} ) . "/.ofac/sdn.sqlite";
Condition33%1/3
$ENV{'HOME'} || $ENV{'USERPROFILE'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$ENV{'HOME'} || $ENV{'USERPROFILE'}
$ENV{'HOME'} $ENV{'USERPROFILE'}
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= $ENV{'USERPROFILE'}
ABresult
1X1
011
000
128 }
129  
130 3 $self->{sdn} = Data::OFAC::SDN->new( p => $self );
131  
132 2 $self->{_status} = $self->{sdn}->{_status};
133  
134 2 return $self;
135  
136 }
137  
138 =head2 checkString
139  
140 Checks the specified string against all fields.
141  
142 my $result = $ofac->checkString("String");
143  
144 =cut
145  
146 0 ▶sub checkString {
Subroutine checkString: not called CC=2 SCAR=17.9
Pod documented
147 0 my $self = shift;
148 0 my $string = shift;
149 0 my $opts = shift;
150  
151 0 my $resultset;
152  
153 0 my @columns = qw{sdn_name title};
154  
155 0 for (qw {Sdn SdnComment}) {
156  
157 0 $resultset->{$_} = $self->{sdn}->search( $_, $string, @columns );
158  
159 }
160  
161 0 @columns = qw{alt_name};
162  
163 0 $resultset->{Alt} = $self->{sdn}->search( 'Alt', $string, @columns );
164  
165 0 @columns = qw{citystateprovincepostalcode country};
166  
167 $resultset->{Address}
168 0 = $self->{sdn}->search( 'Address', $string, @columns );
169  
170 0 return $resultset;
171 }
172  
173 =head2 checkAddress
174  
175 Checks the specified array against the address table. Note the Country must be
176 spelled out I.E. Nigeria
177  
178 my $result =
179 $ofac->checkAddress("City, State, Province, Postal Code", "Country");
180  
181 =cut
182  
183 0 ▶sub checkAddress {
Subroutine checkAddress: not called CC=1 SCAR=6.9
Pod documented
184 0 my $self = shift;
185 0 my $address = shift;
186 0 my $country = shift;
187  
188 0 return $self->{sdn}->searchAddress( $address, $country );
189 }
190  
191 =head2 checkName
192  
193 Checks the specified name against the SDN and ALT tables. Note that for the
194 best match, supply an individual's name in "Lastname, Firstname" format. For
195 corporations, supply in regular format.
196  
197 =cut
198  
199 1 ▶sub checkName {
Subroutine checkName: called CC=2 SCAR=7.6
Pod documented
200 1 my $self = shift;
201 1 my $name = shift;
202  
203 1 my $resultset;
204  
205 1 my @columns = qw{sdn_name title};
206  
207 1 for (qw {Sdn SdnComment}) {
208  
209 1 $resultset->{$_} = $self->{sdn}->search( $_, $name, @columns );
210  
211 }
212  
213 0 @columns = qw{alt_name};
214  
215 0 $resultset->{Alt} = $self->{sdn}->search( 'Alt', $name, @columns );
216  
217 0 return $resultset;
218 }
219  
220 =head2 checkStatus
221  
222 Checks for the database status after startup. Returns "dirty" or "clean". Handy
223 for determining the validity of the data being returned. Dirty just indicates
224 that the database hasn't been updated recently.
225  
226 =cut
227  
228 0 ▶sub checkStatus {
Subroutine checkStatus: not called CC=1 SCAR=6.9
Pod documented
229 0 return $_->{_status};
230 }
231  
232 =head2 willUpdate
233  
234 Checks if the next search call will force a database update. If yes, the call
235 will return "defined" or 1. Helpful if your application is timing sensitive to
236 prespin the update before your next search. Note that at this time, updating is
237 a blocking call.
238  
239 =cut
240  
241 0 ▶sub willUpdate {
Subroutine willUpdate: not called CC=2 SCAR=17.9
Pod documented
242  
243 ( time() - $_->{sdn}->{_lastupdate} )
244 0 ▶ >= ( $_->{auto_update_frequency} * 60 * 60 )
Branch: 1 branch
BranchTrueFalseTotal
time - $_->{"sdn"}{"_lastupdate"} >= $_->{"auto_update_frequency"} * 60 * 60 and return 1 0 0 0
245 && return 1;
246  
247 0 return undef;
248 }
249  
250 =head2 forceUpdate
251  
252 Force the update of the database. Will cause a database update to occur. Note
253 that this call still blocks, but is handy if you want an out-of-band process
254 to handle the updating.
255  
256 =cut
257  
258 0 ▶sub forceUpdate {
Subroutine forceUpdate: not called CC=1 SCAR=6.9
Pod documented
259 0 my $self = shift;
260 0 return $self->{sdn}->updateDatabase();
261 }
262  
263 =head1 AUTHOR
264  
265 tyler hardison, C<< <tyler at seraph-net.net> >>
266  
267 =head1 BUGS
268  
269 Please report any bugs or feature requests to C<bug-data-ofac at rt.cpan.org>, or through
270 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-OFAC>. I will be notified, and then you'll
271 automatically be notified of progress on your bug as I make changes.
272  
273  
274  
275  
276 =head1 SUPPORT
277  
278 You can find documentation for this module with the perldoc command.
279  
280 perldoc Data::OFAC
281  
282  
283 You can also look for information at:
284  
285 =over 4
286  
287 =item * RT: CPAN's request tracker (report bugs here)
288  
289 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-OFAC>
290  
291 =item * AnnoCPAN: Annotated CPAN documentation
292  
293 L<http://annocpan.org/dist/Data-OFAC>
294  
295 =item * CPAN Ratings
296  
297 L<http://cpanratings.perl.org/d/Data-OFAC>
298  
299 =item * Search CPAN
300  
301 L<http://search.cpan.org/dist/Data-OFAC/>
302  
303 =back
304  
305  
306 =head1 ACKNOWLEDGEMENTS
307  
308  
309 =head1 LICENSE AND COPYRIGHT
310  
311 Copyright 2013 Tyler Hardison.
312  
313 This program is free software; you can redistribute it and/or modify it
314 under the terms of the the Artistic License (2.0). You may obtain a
315 copy of the full license at:
316  
317 L<http://www.perlfoundation.org/artistic_license_2_0>
318  
319 Any use, modification, and distribution of the Standard or Modified
320 Versions is governed by this Artistic License. By using, modifying or
321 distributing the Package, you accept this license. Do not use, modify,
322 or distribute the Package, if you do not accept this license.
323  
324 If your Modified Version has been derived from a Modified Version made
325 by someone other than you, you are nevertheless required to ensure that
326 your Modified Version complies with the requirements of this license.
327  
328 This license does not grant you the right to use any trademark, service
329 mark, tradename, or logo of the Copyright Holder.
330  
331 This license includes the non-exclusive, worldwide, free-of-charge
332 patent license to make, have made, use, offer to sell, sell, import and
333 otherwise transfer the Package with respect to any patent claims
334 licensable by the Copyright Holder that are necessarily infringed by the
335 Package. If you institute patent litigation (including a cross-claim or
336 counterclaim) against any party alleging that the Package constitutes
337 direct or contributory patent infringement, then this Artistic License
338 to you shall terminate on the date that such litigation is filed.
339  
340 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
341 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
342 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
343 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
344 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
345 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
346 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
347 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
348  
349  
350 =cut
351  
352 4 1; # End of Data::OFAC
« OFAC/SDN.pm ↑ Summary OFAC/SDN/Schema.pm »