| 1 | package Business::SWIFT; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Locales ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Business::SWIFT - Validate SWIFT/BIC Bank identifiers. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.01 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | This module implements the SWIFT BIC format validation. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | It checks if the given SWIFT BIC code is well-formed according | ||||||||||||||||||||||||||||
| 25 | to the ISO 9362 Specification. It does not check if the code is a | ||||||||||||||||||||||||||||
| 26 | valid actual bank code. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | use Business::SWIFT; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | if ( Business::SWIFT->validateBIC('DEUTDEFF') ){ | ||||||||||||||||||||||||||||
| 32 | .. do stuff .. | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Based on the following specification: | ||||||||||||||||||||||||||||
| 37 | http://en.wikipedia.org/wiki/ISO_9362 | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 validateBIC | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Returns a true value if the given BIC code is correct. False otherwise. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Code letters have to be uppercase. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | This is a class method. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Usage example: | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | if ( Business::SWIFT->validateBIC('DEUTDEFF') ){ | ||||||||||||||||||||||||||||
| 53 | .. do stuff .. | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 14 | ▶ | sub validateBIC{ | ||||||||||||||||||||||||||
|
Subroutine
validateBIC: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 14 | my ( $class , $candidate ) = @_ ; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 14 | my $candLength = length($candidate) ; | |||||||||||||||||||||||||||
| 63 | 14 | ▶ | if( ( 8 != $candLength ) && ( 11 != $candLength ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
8 != $candLength and 11 != $candLength
MC/DC100%2/2
8 != $candLength and 11 != $candLength
8 != $candLength
11 != $candLength
Truth table100%3/3
A and B
A= 8 != $candLengthB= 11 != $candLength
| |||||||||||||||||||||||||||||
| 64 | 1 | return 0; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 13 | my ( $bankCode , $countryCode , | |||||||||||||||||||||||||||
| 68 | $locationCode , $branchCode ) = ( $candidate =~ /^([A-Z]{4})([A-Z]{2})([A-Z0-9]{2})([A-Z0-9]{3})?/ ); | ||||||||||||||||||||||||||||
| 69 | 13 | ▶ | if( ! $bankCode ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2 | return 0; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 11 | my $en = Locales->new( "en" ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 11 | ▶ | if ( ! $en->get_territory_from_code( $countryCode ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | return 0; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 10 | ▶ | if ( ! $locationCode ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | return 0; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 10 | ▶ | if ( ( $candLength == 11 ) && ( ! $branchCode ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$candLength == 11 and not $branchCode
MC/DC100%2/2
$candLength == 11 and not $branchCode
$candLength == 11
not $branchCode
Truth table100%3/3
A and not(B)
A= $candLength == 11B= not $branchCode
| |||||||||||||||||||||||||||||
| 84 | 1 | return 0; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | ## All is correct | ||||||||||||||||||||||||||||
| 88 | 9 | return 1; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Jerome Eteve C<< <jerome at eteve.net> >> | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 99 | C<bug-business-swift at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 100 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Business-SWIFT>. | ||||||||||||||||||||||||||||
| 101 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 102 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | perldoc Business::SWIFT | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | You can also look for information at: | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =over 4 | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | L<http://annocpan.org/dist/Business-SWIFT> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | L<http://cpanratings.perl.org/d/Business-SWIFT> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-SWIFT> | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | L<http://search.cpan.org/dist/Business-SWIFT> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =back | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Copyright 2009 Careerjet, all rights reserved. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 139 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 3 | 1; # End of Business::SWIFT | |||||||||||||||||||||||||||