| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojolicious::Plugin::Vparam::ISIN; | 
| 2 | 72 |  |  | 72 |  | 537645 | use Mojo::Base -strict; | 
|  | 72 |  |  |  |  | 8313 |  | 
|  | 72 |  |  |  |  | 585 |  | 
| 3 | 72 |  |  | 72 |  | 9209 | use Mojolicious::Plugin::Vparam::Common qw(char_shift); | 
|  | 72 |  |  |  |  | 164 |  | 
|  | 72 |  |  |  |  | 54625 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | sub check_isin($) { | 
| 6 | 10 | 50 |  | 10 | 0 | 28 | return 'Value not defined'      unless defined $_[0]; | 
| 7 | 10 | 100 |  |  |  | 41 | return 'Value not set'          unless length  $_[0]; | 
| 8 | 9 | 50 |  |  |  | 53 | return 'Wrong format'           unless $_[0] =~ m{^[A-Z0-9]+$}; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 9 |  |  |  |  | 23 | my $str = $_[0]; | 
| 11 | 9 |  |  |  |  | 31 | my $ch  = char_shift(); | 
| 12 | 9 |  |  |  |  | 50 | s{([A-Z])}{(ord($1)-$ch)}eg for $str; | 
|  | 15 |  |  |  |  | 106 |  | 
| 13 | 9 |  |  |  |  | 21 | my $crc = 0; | 
| 14 | 9 |  |  |  |  | 74 | my @str = reverse split '', $str; | 
| 15 | 9 |  |  |  |  | 40 | for my $i ( 0 .. $#str  ) { | 
| 16 | 130 |  |  |  |  | 206 | my $digit = $str[$i]; | 
| 17 | 130 | 100 |  |  |  | 288 | $digit *= 2 if $i % 2; | 
| 18 | 130 | 100 |  |  |  | 292 | $digit -= 9 if $digit > 9; | 
| 19 | 130 |  |  |  |  | 313 | $crc += $digit; | 
| 20 |  |  |  |  |  |  | } | 
| 21 | 9 | 100 |  |  |  | 29 | return 'Checksum error'         if $crc % 10; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 8 |  |  |  |  | 48 | return 0; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub check_maestro { | 
| 27 | 3 | 50 |  | 3 | 0 | 9 | return 'Value not defined'      unless defined $_[0]; | 
| 28 | 3 | 100 |  |  |  | 15 | return 'Value not set'          unless length  $_[0]; | 
| 29 | 2 | 50 |  |  |  | 12 | return 'Wrong format'           unless $_[0] =~ m{^\d+$}; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 2 |  |  |  |  | 9 | return 0; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub check_creditcard { | 
| 35 | 5 | 50 |  | 5 | 0 | 12 | return 'Value not defined'      unless defined $_[0]; | 
| 36 | 5 | 100 |  |  |  | 16 | return 'Value not set'          unless length  $_[0]; | 
| 37 | 4 | 100 |  |  |  | 25 | return 'Wrong format'           unless $_[0] =~ m{^\d+$}; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2 |  |  |  |  | 8 | return 0; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub parse_isin($) { | 
| 43 | 15 |  |  | 15 | 0 | 38 | my ($str) = @_; | 
| 44 | 15 | 50 |  |  |  | 44 | return undef unless defined $str; | 
| 45 | 15 |  |  |  |  | 97 | s{[^a-zA-Z0-9]}{}g for $str; | 
| 46 | 15 |  |  |  |  | 78 | return uc $str; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub parse_maestro($) { | 
| 50 | 3 |  |  | 3 | 0 | 9 | my ($str) = @_; | 
| 51 | 3 | 50 |  |  |  | 8 | return undef unless defined $str; | 
| 52 | 3 |  |  |  |  | 23 | s{\D+}{}g for $str; | 
| 53 | 3 |  |  |  |  | 10 | return $str; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub parse_creditcard($) { | 
| 57 | 5 |  |  | 5 | 0 | 12 | return parse_isin $_[0]; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub register { | 
| 61 | 74 |  |  | 74 | 0 | 265 | my ($class, $self, $app, $conf) = @_; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | $app->vtype( | 
| 64 |  |  |  |  |  |  | isin        => | 
| 65 | 10 |  |  | 10 |  | 36 | pre     => sub { parse_isin         $_[1] }, | 
| 66 | 10 |  |  | 10 |  | 33 | valid   => sub { check_isin         $_[1] }, | 
| 67 | 74 |  |  |  |  | 815 | ); | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | $app->vtype( | 
| 70 |  |  |  |  |  |  | maestro     => | 
| 71 | 3 |  |  | 3 |  | 32 | pre     => sub { parse_maestro      $_[1] }, | 
| 72 | 3 |  |  | 3 |  | 9 | valid   => sub { check_maestro      $_[1] }, | 
| 73 | 74 |  |  |  |  | 781 | ); | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | $app->vtype( | 
| 76 |  |  |  |  |  |  | creditcard  => | 
| 77 | 5 |  |  | 5 |  | 13 | pre     => sub { parse_creditcard   $_[1] }, | 
| 78 | 5 |  |  | 5 |  | 12 | valid   => sub { check_creditcard   $_[1] }, | 
| 79 | 74 |  |  |  |  | 697 | ); | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 74 |  |  |  |  | 319 | return; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | 1; |