App-Basis-ConvertText2
view release on metacpan or search on metacpan
lib/App/Basis/ConvertText2/Plugin/Barcode.pm view on Meta::CPAN
=head1 NAME
App::Basis::ConvertText::Plugin::Barcode
=head1 SYNOPSIS
my $content = "12345678" ;
my $params = {
type => "EAN8"
} ;
my $obj = App::Basis::ConvertText2::Plugin::Barcode->new() ;
my $out = $obj->process( 'barcode', $content, $params) ;
=head1 DESCRIPTION
convert a text string into a QRcode PNG, requires qrencode program
=cut
# ----------------------------------------------------------------------------
package App::Basis::ConvertText2::Plugin::Barcode;
$App::Basis::ConvertText2::Plugin::Barcode::VERSION = '0.4';
use 5.10.0;
use strict;
use warnings;
use Path::Tiny;
use Capture::Tiny ':all';
use Image::Resize;
use GD::Barcode;
use Moo;
use App::Basis;
use App::Basis::ConvertText2::Support;
use namespace::autoclean;
has handles => (
is => 'ro',
init_arg => undef,
default => sub { [qw{qrcode barcode}] }
);
use constant QRCODE => 'qrencode';
my @_barcodes = (
qw(Code39 EAN13 EAN8 COOP2of5 IATA2of5 Industrial2of5
ITF Matrix2of5 NW7 QRcode UPCA UPCE)
);
my %valid_barcodes = map { lc($_) => $_ } @_barcodes;
# ----------------------------------------------------------------------------
=item barcode
create a qrcode image, just use default options for now
parameters
filename - filename to save the created image as
hashref params of
size - size of image, widthxheight - optional
version - version of the qrcode to create, defaults to 2
pixels - number of pixels that make a bit, defaults to 2
=cut
sub process {
my $self = shift;
my ( $tag, $content, $params, $cachedir ) = @_;
my $qrcode ;
# we have a special tag handler for qrcodes
if ( $tag eq 'qrcode' ) {
$params->{type} = 'QRcode';
$qrcode->{Version} = $params->{version} || 2 ;
$qrcode->{ModuleSize} = $params->{pixels} || 2 ;
}
# strip any ending linefeed
chomp $content;
return "" if ( !$content );
# get the type as BG::Barcode understands it
my $type = $valid_barcodes{ lc($params->{type}) } ;
# check if we can process this barcode
if ( !$type ) {
warn "$params->{type} is not a valid barcode type";
# let the caller put the block back together
return undef;
}
# we can use the cache or process everything ourselves
( run in 0.587 second using v1.01-cache-2.11-cpan-39bf76dae61 )