Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cf269e87

Von Steven Schubiger vor 5 Tagen hinzugefügt

  • ID cf269e874a5364e36c73aed64ed3176527ea8990
  • Vorgänger d401110b

Swiss QR-Bill: QrBill.pm: Verschiebe Reguläre Ausdrücke in interne Subroutine _get_regexes()

Unterschiede anzeigen:

SL/Helper/QrBill.pm
9 9
use Imager ();
10 10
use Imager::QRCode ();
11 11

  
12
our $VERSION = '0.01';
12
our $VERSION = '0.02';
13 13

  
14 14
my %Config = (
15 15
  img_dir    => 'image',
......
79 79
  ];
80 80
}
81 81

  
82
# Validate the data with regular expressions and exit ungracefully
83
# if conditions are not matched.
84
sub _init_check {
85
  my $self = shift;
86
  my ($biller_information, $biller_data, $payment_information, $invoice_recipient_data, $ref_nr_data, $additional_information) = @_;
87

  
88
  my $check_re = sub {
89
    my ($group, $href, $elem, $regex) = @_;
90
    my $error = undef;
91
    if (!exists $href->{$elem}) {
92
      $error = 'does not exist';
93
    } elsif (!defined $href->{$elem}) {
94
      $error = 'is not defined';
95
    } elsif ($href->{$elem} !~ $regex) {
96
      $error = 'is not valid';
97
    }
98
    die "field '$elem' in group '$group' $error", "\n" if defined $error;
99
  };
100

  
101
  my %regexes = (
82
# Return the regular expressions used for validating data.
83
sub _get_regexes {
84
  return (
102 85
    'biller information' => [
103 86
      [ 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$} ],
104 87
    ],
......
142 125
      'qr_iban' => qr{^.{4}3[01][0-9]{3}.{12}$},
143 126
    },
144 127
  );
128
}
129

  
130
# Validate the data with regular expressions and exit ungracefully
131
# if conditions are not matched.
132
sub _init_check {
133
  my $self = shift;
134
  my ($biller_information, $biller_data, $payment_information, $invoice_recipient_data, $ref_nr_data, $additional_information) = @_;
135

  
136
  my $check_re = sub {
137
    my ($group, $href, $elem, $regex) = @_;
138
    my $error = undef;
139
    if (!exists $href->{$elem}) {
140
      $error = 'does not exist';
141
    } elsif (!defined $href->{$elem}) {
142
      $error = 'is not defined';
143
    } elsif ($href->{$elem} !~ $regex) {
144
      $error = 'is not valid';
145
    }
146
    die "field '$elem' in group '$group' $error", "\n" if defined $error;
147
  };
148

  
149
  my %regexes = _get_regexes();
145 150

  
146 151
  my $group = 'biller information';
147 152
  foreach my $re (@{$regexes{$group}}) {

Auch abrufbar als: Unified diff