#!/usr/local/bin/perl

use strict;
use CGI qw(-nosticky);
use GD::Barcode::QRcode;

my $q = CGI->new();

my $me = $ENV{SCRIPT_NAME};

if( (my $string=$q->param('string')) && (my $level=$q->param('level')) ){
    # ecc = l m q h
    # version = 1 .. 40

    # modify /usr/local/lib/perl5/site_perl/5.8.9/GD/Barcode/QRcode.pm
    # -$oSelf->{Version} = $rhPrm->{Version} || 1;
    # +$oSelf->{Version} = $rhPrm->{Version} || 0;
    # then use Version => undef, below

    my $qr = GD::Barcode::QRcode->new($string, {
                                                 Ecc        => $level,
                                                 Version    => undef,
                                                 ModuleSize => 8,
                                                } );
    print $q->header(-expires => 'now', '-Content-Type' => 'image/png'),
          $qr->plot->png;
}else{
    print $q->header(-expires => 'now'),
          $q->start_html(), "\n",
          $q->start_form('POST', $me), "\n",
          'Code:<br> <textarea name="string" maxlength="4296"></textarea>', "<br>\n",
          'Redundancy Level: <select name="level">', "\n",
          ' <option value="L">7%</option>', "\n",
          ' <option selected value="M">15%</option>', "\n",
          ' <option value="Q">25%</option>', "\n",
          ' <option value="H">30%</option>', "\n",
          "</select>\n",
          "<br>\n",
          $q->submit(), "<br>\n",
          $q->end_form();
}
