Debian Codegraph @

cgi-bin/checkdigits.cgi

raw
1 #!/usr/bin/perl -w
2 # vim: ts=4 sw=4 tw=78 et si:
3 #
4 use strict;
5
6 use Algorithm::CheckDigits;
7 use CGI qw(:standard);
8 use CGI::Carp qw(fatalsToBrowser);
9
10 my $algorithm = param('algorithm');
11 my $number = param('number');
12 my $ok = '';
13 my @all_algorithms;
14 my %all_labels;
15
16 if ($ENV{ALL_ALGORITHMS}) {
17 @all_algorithms = split /,/, $ENV{ALL_ALGORITHMS};
18 }
19 else {
20 @all_algorithms = Algorithm::CheckDigits::method_list();
21 }
22
23 %all_labels = Algorithm::CheckDigits::method_descriptions(@all_algorithms);
24
25 if ($number and $algorithm) {
26 my $cd = CheckDigits($algorithm);
27 if ($cd->is_valid($number)) {
28 $ok = "$number is a valid $algorithm number";
29 param('number','');
30 }
31 else {
32 $ok = "$number is not valid with algorithm $algorithm";
33 }
34 }
35
36 print header(),
37 start_html(),
38 start_form(),
39 textfield('number'),
40 popup_menu(-name => 'algorithm',
41 -values => \@all_algorithms,
42 -labels => \%all_labels),
43 submit('check'),
44 end_form(),
45 $ok,
46 end_html(),
47 "\n";
48
49 exit 0;