| 1 | package SVG::Barcode::QRCode; | ||
| 2 | 2 | ▶ | use parent 'SVG::Barcode'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use v5.24; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 2 | ▶ | use feature 'signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | no warnings 'experimental::signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | ▶ | use Exporter 'import'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | our @EXPORT_OK = qw|plot_qrcode|; | ||
| 12 | |||
| 13 | 2 | ▶ | use Text::QRCode; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 14 | |||
| 15 | our $VERSION = '0.03'; | ||
| 16 | |||
| 17 | use constant DEFAULTS => { | ||
| 18 | background => 'white', | ||
| 19 | foreground => 'black', | ||
| 20 | level => 'M', | ||
| 21 | margin => 10, | ||
| 22 | size => 5, | ||
| 23 | version => 0, | ||
| 24 | }; | ||
| 25 | |||
| 26 | # functions | ||
| 27 | |||
| 28 | sub plot_qrcode ($text, $params = {}) { | ||
| 29 | return __PACKAGE__->new($params)->plot($text); | ||
| 30 | } | ||
| 31 | |||
| 32 | # internal methods | ||
| 33 | |||
| 34 | sub _plot ($self, $text) { | ||
| 35 | $self->{plotter} ||= Text::QRCode->new($self->%{qw|level version|}); | ||
| 36 | |||
| 37 | $self->_plot_2d($self->{plotter}->plot($text), '*'); | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | =encoding utf8 | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | SVG::Barcode::QRCode - Generator for SVG based QR Codes | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use SVG::Barcode::QRCode; | ||
| 51 | |||
| 52 | my %params = ( # defaults | ||
| 53 | background => 'white', | ||
| 54 | foreground => 'black', | ||
| 55 | level => 'M', | ||
| 56 | margin => 10, | ||
| 57 | size => 5, | ||
| 58 | version => 0, | ||
| 59 | ); | ||
| 60 | my $qrcode = SVG::Barcode::QRCode->new(\%params); | ||
| 61 | my $svg = $qrcode->plot('https://perldoc.pl'); | ||
| 62 | my $svg2 = $qrcode->param(foreground => 'red')->plot('https://perldoc.pl'); | ||
| 63 | |||
| 64 | # use as function | ||
| 65 | use SVG::Barcode::QRCode 'plot_qrcode'; | ||
| 66 | |||
| 67 | my $svg = plot_qrcode('https://perldoc.pl', \%params); | ||
| 68 | |||
| 69 | =head1 DESCRIPTION | ||
| 70 | |||
| 71 | L<SVG::Barcode::QRCode> is a generator for SVG based QR Codes. | ||
| 72 | |||
| 73 | =head1 FUNCTIONS | ||
| 74 | |||
| 75 | =head2 plot_qrcode | ||
| 76 | |||
| 77 | use SVG::Barcode::QRCode 'plot_qrcode'; | ||
| 78 | |||
| 79 | my $svg = plot_qrcode($text, \%params); | ||
| 80 | |||
| 81 | Returns a QR Code using the provided text and parameters. | ||
| 82 | |||
| 83 | =head1 CONSTRUCTOR | ||
| 84 | |||
| 85 | =head2 new | ||
| 86 | |||
| 87 | $qrcode = SVG::Barcode::QRCode->new(\%params); | ||
| 88 | $qrcode = SVG::Barcode::QRCode->new; # create with defaults | ||
| 89 | |||
| 90 | Creates a new QR Code plotter. Inherited from L<SVG::Barcode/new>. | ||
| 91 | |||
| 92 | Accepted parameters are: | ||
| 93 | |||
| 94 | =over 4 | ||
| 95 | |||
| 96 | =item background | ||
| 97 | |||
| 98 | Color of the background. Default C<'white'>. | ||
| 99 | |||
| 100 | =item foreground | ||
| 101 | |||
| 102 | Color of the dots. Default C<'black'>. | ||
| 103 | |||
| 104 | =item level | ||
| 105 | |||
| 106 | Error correction level, one of C<'L'> (low), C<'M'> (medium), C<'Q'> (quartile), C<'H'> (high). Default C<'M'>. | ||
| 107 | |||
| 108 | =item margin | ||
| 109 | |||
| 110 | Margin around the code. Default C<10>. | ||
| 111 | |||
| 112 | =item size | ||
| 113 | |||
| 114 | Size of the dots. Default C<5>. | ||
| 115 | |||
| 116 | =item version | ||
| 117 | |||
| 118 | Symbol version from C<1> to C<40>. C<0> will adapt the version to the required capacity. Default C<0>. | ||
| 119 | |||
| 120 | =back | ||
| 121 | |||
| 122 | =head1 METHODS | ||
| 123 | |||
| 124 | =head2 param | ||
| 125 | |||
| 126 | Getter and setter for the parameters. Inherited from L<SVG::Barcode/param>. | ||
| 127 | |||
| 128 | =head2 plot | ||
| 129 | |||
| 130 | Creates a SVG code. Inherited from L<SVG::Barcode/plot>. | ||
| 131 | |||
| 132 | =head1 SEE ALSO | ||
| 133 | |||
| 134 | L<SVG::Barcode>, L<Text::QRCode>. | ||
| 135 | |||
| 136 | =head1 AUTHOR & COPYRIGHT | ||
| 137 | |||
| 138 | © 2019 by Tekki (Rolf Stöckli). | ||
| 139 | |||
| 140 | This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. | ||
| 141 | |||
| 142 | =cut | ||