HTML::QRCode - Generate HTML based QR Code


HTML-QRCode documentation Contained in the HTML-QRCode distribution.

Index


Code Index:

NAME

Top

HTML::QRCode - Generate HTML based QR Code

SYNOPSIS

Top

  #!/usr/bin/env perl

  use HTML::QRCode;
  use CGI

  my $q = CGI->new;
  my $text = $q->param('text') || 'http://example.com/';
  my $qrcode = HTML::QRCode->new->plot($text);
  print $q->header;
  print <<"HTML";
  <html>
  <head></head>
  <body>
  $qrcode
  </body>
  </html>
  HTML

DESCRIPTION

Top

HTML::QRCode is HTML based QRCode generator, using Text::QRCode

METHODS

Top

new
    $qrcode = HTML::QRCode->new(%params);

The new() constructor method instantiates a new Term::QRCode object.

plot($text)
    $arrayref = $qrcode->plot("blah blah");

Return HTML based QR Code.

AUTHOR

Top

Hideo Kimura <hide <at> hide-k.net>

Yoshiki Kurihara

Yappo

nipotan

SEE ALSO

Top

Text::QRCode, Imager::QRCode, Term::QRCode, HTML::QRCode, http://www.qrcode.com/, http://megaui.net/fukuchi/works/qrencode/index.en.html

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


HTML-QRCode documentation Contained in the HTML-QRCode distribution.

package HTML::QRCode;

use strict;
use warnings;
our $VERSION = '0.01';

use Text::QRCode;
use Carp;

sub new {
    my ( $class, %args ) = @_;

    bless {
        text_qrcode => Text::QRCode->new,
        white => 'white',
        black => 'black',
        %args
    }, $class;
}

sub plot {
    my ( $self, $text ) = @_;
    croak 'Not enough arguments for plot()' unless $text;

    my $arref = $self->{text_qrcode}->plot($text);

    my ($white, $black) = ($self->{white}, $self->{black});
    my $w = "<td style=\"border:0;margin:0;padding:0;width:3px;height:3px;background-color: $white;\">";
    my $b = "<td style=\"border:0;margin:0;padding:0;width:3px;height:3px;background-color: $black;\">";

    my $html
        .= '<table style="margin:0;padding:0;border-width:0;border-spacing:0;">';
    $html
        .= '<tr style="border:0;margin:0;padding:0;">'
        . join( '', map { $_ eq '*' ? $b : $w } @$_ ) . '</tr>'
        for (@$arref);
    $html .= '</table>';

    return $html;
}

1;
__END__