| 1 | package Finance::MIFIR::CONCAT; | ||
| 2 | 2 | ▶ | use 5.014; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | our $VERSION = '0.01'; | |
| 7 | |||
| 8 | 2 | ▶ | use Date::Utility; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use Exporter 'import'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use File::ShareDir; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 2 | ▶ | use YAML::XS qw/LoadFile/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 2 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 2 | our @EXPORT_OK = qw(mifir_concat); | |
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | Finance::MIFIR::CONCAT - provides CONCAT code generation out of client data according to MIFIR rules | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | use Finance::MIFIR::CONCAT qw/mifir_concat/; | ||
| 22 | |||
| 23 | print mifir_concat({ | ||
| 24 | cc => 'DE', | ||
| 25 | date => '1960-01-01', | ||
| 26 | first_name => 'Jack', | ||
| 27 | last_name => 'Daniels', | ||
| 28 | }); | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | =head2 mifir_concat | ||
| 35 | |||
| 36 | Accepts hashref of person's data with keys: cc, date, first_name, last_name. | ||
| 37 | |||
| 38 | Returns string representing CONCATed MIFIR ID. | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | 2 | our $config = LoadFile(File::ShareDir::dist_file('Finance-MIFIR-CONCAT', 'mifir.yml')); | |
| 43 | 2 | our $romanization = LoadFile(File::ShareDir::dist_file('Finance-MIFIR-CONCAT', 'romanization.yml')); | |
| 44 | |||
| 45 | sub mifir_concat { | ||
| 46 | 3 | ▶ | my $args = shift; |
|
Subroutine
mifir_concat: called CC=1 SCAR=0.0
Pod
documented
| |||
| 47 | 3 | my $cc = $args->{cc}; | |
| 48 | 3 | my $date = Date::Utility->new($args->{date})->date_yyyymmdd; | |
| 49 | 3 | $date =~ s/\-//g; | |
| 50 | 3 | my $first_name = _process_name($args->{first_name}); | |
| 51 | 3 | my $last_name = _process_name($args->{last_name}); | |
| 52 | 3 | return uc($cc . $date . $first_name . $last_name); | |
| 53 | } | ||
| 54 | |||
| 55 | sub _process_name { | ||
| 56 | 40 | ▶ | my ($str) = @_; |
|
Subroutine
_process_name: called CC=1 SCAR=0.0
| |||
| 57 | 40 | $str = lc($str); | |
| 58 | 40 | my $strip_re = join "|", (@{$config->{titles}}, @{$config->{prefixes}}); | |
| 59 | 40 | $strip_re = qr/($strip_re)\s+/; | |
| 60 | 40 | $str =~ s/$strip_re//g; | |
| 61 | 40 | my $re = join '', keys %$romanization; | |
| 62 | 40 | $re = qr/([$re])/; | |
| 63 | 40 | $str =~ s/$re/$romanization->{$1}/ge; | |
| 64 | 40 | $str =~ s/[^a-z]//g; | |
| 65 | 40 | $str = substr($str . '######', 0, 5); | |
| 66 | 40 | return $str; | |
| 67 | } | ||
| 68 | |||
| 69 | 2 | 1; | |