Revision d71cd45c
Von Steven Schubiger vor 6 Tagen hinzugefügt
- ID d71cd45c2598fa3f76e452da8a213c7bcebf67cc
- Vorgänger e6b4cc72
SL/Helper/QrBill.pm | ||
---|---|---|
use Imager ();
|
||
use Imager::QRCode ();
|
||
|
||
our $VERSION = '0.01';
|
||
our $VERSION = '0.02';
|
||
|
||
my %Config = (
|
||
img_dir => 'image',
|
||
... | ... | |
];
|
||
}
|
||
|
||
# Validate the data with regular expressions and exit ungracefully
|
||
# if conditions are not matched.
|
||
sub _init_check {
|
||
my $self = shift;
|
||
my ($biller_information, $biller_data, $payment_information, $invoice_recipient_data, $ref_nr_data, $additional_information) = @_;
|
||
|
||
my $check_re = sub {
|
||
my ($group, $href, $elem, $regex) = @_;
|
||
my $error = undef;
|
||
if (!exists $href->{$elem}) {
|
||
$error = 'does not exist';
|
||
} elsif (!defined $href->{$elem}) {
|
||
$error = 'is not defined';
|
||
} elsif ($href->{$elem} !~ $regex) {
|
||
$error = 'is not valid';
|
||
}
|
||
die "field '$elem' in group '$group' $error", "\n" if defined $error;
|
||
};
|
||
|
||
my %regexes = (
|
||
# Return the regular expressions used for validating data.
|
||
sub _get_regexes {
|
||
return (
|
||
'biller information' => [
|
||
[ 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$} ],
|
||
],
|
||
... | ... | |
'qr_iban' => qr{^.{4}3[01][0-9]{3}.{12}$},
|
||
},
|
||
);
|
||
}
|
||
|
||
# Validate the data with regular expressions and exit ungracefully
|
||
# if conditions are not matched.
|
||
sub _init_check {
|
||
my $self = shift;
|
||
my ($biller_information, $biller_data, $payment_information, $invoice_recipient_data, $ref_nr_data, $additional_information) = @_;
|
||
|
||
my $check_re = sub {
|
||
my ($group, $href, $elem, $regex) = @_;
|
||
my $error = undef;
|
||
if (!exists $href->{$elem}) {
|
||
$error = 'does not exist';
|
||
} elsif (!defined $href->{$elem}) {
|
||
$error = 'is not defined';
|
||
} elsif ($href->{$elem} !~ $regex) {
|
||
$error = 'is not valid';
|
||
}
|
||
die "field '$elem' in group '$group' $error", "\n" if defined $error;
|
||
};
|
||
|
||
my %regexes = _get_regexes();
|
||
|
||
my $group = 'biller information';
|
||
foreach my $re (@{$regexes{$group}}) {
|
Auch abrufbar als: Unified diff
Swiss QR-Bill: QrBill.pm: Verschiebe Reguläre Ausdrücke in interne Subroutine _get_regexes()