Skip to content

Commit

Permalink
Swiss QR-Bill: QrBill.pm: Verschiebe Reguläre Ausdrücke in interne Su…
Browse files Browse the repository at this point in the history
…broutine _get_regexes()
  • Loading branch information
stsc authored and rebootl committed Dec 18, 2024
1 parent 15aacde commit e6500be
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions SL/Helper/QrBill.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use File::Spec ();
use Imager ();
use Imager::QRCode ();

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

my %Config = (
img_dir => 'image',
Expand Down Expand Up @@ -79,26 +79,9 @@ sub _init {
];
}

# 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}$} ],
],
Expand Down Expand Up @@ -142,6 +125,28 @@ sub _init_check {
'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}}) {
Expand Down

0 comments on commit e6500be

Please sign in to comment.