blib/lib/Finance/MIFIR/CONCAT.pm

filter: Statementstmt 100% 50 / 50 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 100% 61 / 61 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
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.02';
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 6 ▶sub mifir_concat {
Subroutine mifir_concat: called CC=1 SCAR=0.0
Pod documented
46 6 my $args = shift;
47 6 my $cc = $args->{cc};
48 6 my $date = Date::Utility->new($args->{date})->date_yyyymmdd;
49 6 $date =~ s/\-//g;
50 6 my $first_name = _process_name($args->{first_name});
51 6 my $last_name = _process_name($args->{last_name});
52 6 return uc($cc . $date . $first_name . $last_name);
53 }
54  
55 46 ▶sub _process_name {
Subroutine _process_name: called CC=1 SCAR=0.0
56 46 my ($str) = @_;
57 46 $str = lc($str);
58  
59 # Remove titles and prefixes with word boundary
60 46 my $strip_re = join "|", (@{$config->{titles}}, @{$config->{prefixes}});
61 46 $strip_re = qr/\b($strip_re)\s+/i;
62 46 $str =~ s/$strip_re//g;
63 46 $str =~ s/\s+.*$//; # Remove everything after first space
64  
65 # Romanization
66 46 my $re = join '', keys %$romanization;
67 46 $re = qr/([$re])/;
68 46 $str =~ s/$re/$romanization->{$1}/ge;
69  
70 # Remove non-alphabetic characters
71 46 $str =~ s/[^a-z]//g;
72  
73 # Pad to 5 characters
74 46 $str = substr($str . '######', 0, 5);
75 46 return $str;
76 }
77 2 1;
↑ Summary