Revision 4a826447
Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt
SL/Common.pm | ||
---|---|---|
511 | 511 |
my $params = shift; |
512 | 512 |
|
513 | 513 |
foreach my $key (@_) { |
514 |
if (!defined $params->{$key}) { |
|
514 |
if ((ref $key eq '') && !defined $params->{$key}) {
|
|
515 | 515 |
my $subroutine = (caller(1))[3]; |
516 | 516 |
$main::form->error($main::locale->text("Missing parameter #1 in call to sub #2.", $key, $subroutine)); |
517 |
|
|
518 |
} elsif (ref $key eq 'ARRAY') { |
|
519 |
my $found = 0; |
|
520 |
foreach $subkey (@{ $key }) { |
|
521 |
if (defined $params->{$subkey}) { |
|
522 |
$found = 1; |
|
523 |
last; |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
if (!$found) { |
|
528 |
my $subroutine = (caller(1))[3]; |
|
529 |
$main::form->error($main::locale->text("Missing parameter (at least one of #1) in call to sub #2.", join(', ', @{ $key }), $subroutine)); |
|
530 |
} |
|
517 | 531 |
} |
518 | 532 |
} |
519 | 533 |
} |
... | ... | |
522 | 536 |
my $params = shift; |
523 | 537 |
|
524 | 538 |
foreach my $key (@_) { |
525 |
if (!exists $params->{$key}) { |
|
539 |
if ((ref $key eq '') && !exists $params->{$key}) {
|
|
526 | 540 |
my $subroutine = (caller(1))[3]; |
527 | 541 |
$main::form->error($main::locale->text("Missing parameter #1 in call to sub #2.", $key, $subroutine)); |
542 |
|
|
543 |
} elsif (ref $key eq 'ARRAY') { |
|
544 |
my $found = 0; |
|
545 |
foreach $subkey (@{ $key }) { |
|
546 |
if (exists $params->{$subkey}) { |
|
547 |
$found = 1; |
|
548 |
last; |
|
549 |
} |
|
550 |
} |
|
551 |
|
|
552 |
if (!$found) { |
|
553 |
my $subroutine = (caller(1))[3]; |
|
554 |
$main::form->error($main::locale->text("Missing parameter (at least one of #1) in call to sub #2.", join(', ', @{ $key }), $subroutine)); |
|
555 |
} |
|
528 | 556 |
} |
529 | 557 |
} |
530 | 558 |
} |
Auch abrufbar als: Unified diff
Parameter-Check-Funktionen Common::check_params() und Common::check_params_x() erweitert, um auch "oder"-Bedigungen zuzulassen, indem die Liste der erwarteten Parameter als Array-Referenz übergeben werden.