#!/usr/bin/perl use strict; #################### main pod documentation begin ################### =head1 NAME Zymonic - Test script to generate barcode using core functionality =head1 SYNOPSIS =head1 DESCRIPTION This script will take in a system name and various options for generating barcodes and will write out a barcode to file. =head1 SUPPORT As in the license, Zymonic is provided without warranty or support unless purchased separately, however... If you email zymonic-support@zednax.com your issue will be noted and may receive a response. For security issues, please contact zymonic-security@zednax.com and someone will respond within 8 working hours. =head1 AUTHOR Alex Masidlover et al. CPAN ID: MODAUTHOR Zednax Limited alex.masidlover@zednax.com http://www.zednax.com =head1 COPYRIGHT This program is free software licensed under the... Zymonic Public License 1.0 The full text of the license can be found in the LICENSE file included with this module. Other licenses may be acceptable if including parts of Zymonic in larger projects, please contact Zednax for details. =head1 SEE ALSO perl(1). =cut #################### main pod documentation end ################### # modules use File::Basename; use Zymonic::Script; use Zymonic::Action; # start a zymonic script print "Setting up...\n"; my $s = Zymonic::Script->new( args => { barcode_value => { type => 'string', required => 'true', description => 'Value to generate barcode for.', }, encoding => { type => 'string', required => 'true', description => 'Encoding to use: Code128 or RoyalMail.', }, output_file => { type => 'string', required => 'true', description => 'Where to generate the image.', }, image_type => { type => 'string', default => 'png', description => 'Image type to generate.', }, margin => { type => 'string', default => '2,2,6,6', description => 'Margin values, in mm, of the form: top,bottom,left,right, e.g. 2,2,6,6', }, width => { type => 'float', default => '96', description => 'Width, in mm', }, height => { type => 'float', default => '16', description => 'Height, in mm', }, line_width => { type => 'float', default => '0.3', description => 'Width of barcode lines, in mm', }, }, ); print "Setup done.\n"; main(); exit(0); #################### subroutine header begin #################### =head2 main Usage : main(); Purpose : main script functionality Returns : nothing Argument : nothing Throws : nothing Comment : See Also : =cut #################### subroutine header end ################### sub main { # get output file and split into dir and file name my $file = $s->get_arg('output_file'); my ( $file_name, $dir, undef ) = fileparse($file); # remove file if it exists, otherwise action will see it and not generate a new file unlink $file if -f $file; # split the margins into parts my @margins = split( ',', $s->get_arg('margin'), 4 ); # setup an action xmldef with desired settings my $action_def = { ZName => { content => 'generate_barcode_test_zname' }, class => "GenerateBarcode", ClassOptions => { Value => { StaticValue => { content => $s->get_arg('barcode_value') } }, Encoding => { content => $s->get_arg('encoding') }, ImageType => { content => $s->get_arg('image_type') }, OutputDirectory => { StaticValue => { content => $dir } }, OutputFileName => { StaticValue => { content => $file_name } }, MarginTop => { StaticValue => { content => $margins[0] } }, MarginBottom => { StaticValue => { content => $margins[1] } }, MarginLeft => { StaticValue => { content => $margins[2] } }, MarginRight => { StaticValue => { content => $margins[3] } }, Width => { StaticValue => { content => $s->get_arg('width') } }, Height => { StaticValue => { content => $s->get_arg('height') } }, LineWidth => { StaticValue => { content => $s->get_arg('line_width') } }, } }; # load the object my $action = Zymonic::Action->new( zname => $action_def->{ZName}->{content}, ident => $action_def->{ZName}->{content}, xmldef => $action_def, config => $s->{config}, ); print "Generating barcode...\n"; # generate the barcode $action->generate_barcode(); print "Done.\n"; }