File: checkdigits.cgi

package info (click to toggle)
libalgorithm-checkdigits-perl 1.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 500 kB
  • sloc: perl: 3,285; makefile: 13
file content (49 lines) | stat: -rwxr-xr-x 1,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl -w
# vim: ts=4 sw=4 tw=78 et si:
#
use strict;

use Algorithm::CheckDigits;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

my $algorithm = param('algorithm');
my $number    = param('number');
my $ok = '';
my @all_algorithms;
my %all_labels;

if ($ENV{ALL_ALGORITHMS}) {
    @all_algorithms = split /,/, $ENV{ALL_ALGORITHMS};
}
else {
    @all_algorithms = Algorithm::CheckDigits::method_list();
}

%all_labels = Algorithm::CheckDigits::method_descriptions(@all_algorithms);

if ($number and $algorithm) {
    my $cd = CheckDigits($algorithm);
    if ($cd->is_valid($number)) {
        $ok =  "$number is a valid $algorithm number";
        param('number','');
    }
    else {
        $ok =  "$number is not valid with algorithm $algorithm";
    }
}

print header(),
      start_html(),
      start_form(),
      textfield('number'),
      popup_menu(-name   => 'algorithm',
      		 -values => \@all_algorithms,
		 -labels => \%all_labels),
      submit('check'),
      end_form(),
      $ok,
      end_html(),
      "\n";

exit 0;