NAME

App::ZofCMS::Plugin::Barcode - plugin to generate various bar codes

SYNOPSIS

In your Main Config File or ZofCMS Template:

plugins => [
    qw/Barcode/
],

# direct output to browser with default values for optional arguments
plug_barcode => {
    code => '12345678901',
},

# or

# save to file with all options set
plug_barcode => {
    code    => '12345678901',
    file    => 'bar.png',
    type    => 'UPCA', # default
    format  => 'png',  # default
    no_text => 0,      # default
    height  => 50,     # default
},

In your HTML::Template template (in case errors occur):

<tmpl_if name='plug_barcode_error'>
    <p>Error: <tmpl_var escape='html' name='plug_barcode_error'></p>
</tmpl_if>

DESCRIPTION

The module is a plugin for App::ZofCMS that provides means to generate various types of barcodes and either output them directly to the browser or save them as an image.

This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS

plugins

plugins => [
    qw/Barcode/
],

Mandatory. You need to add the plugins to the list of plugins to execute. Note: if you're outputting directly to the browser instead of saving the barcode into a file, the plugin will call exit() as soon as it finishes print()ing the image UNLESS an error occured, so make sure to run anything that needs to be run before that point.

plug_barcode

# direct output to browser with default values for optional arguments
plug_barcode => {
    code => '12345678901',
},

# save to file with all options set
plug_barcode => {
    code    => '12345678901',
    file    => 'bar.png',
    type    => 'UPCA', # default
    format  => 'png',  # default
    no_text => 0,      # default
    height  => 50,     # default
},

Mandatory. Specifies plugin's options. Takes a hashref as a value. Possible keys/values are as follows:

code

plug_barcode => {
    code    => '12345678901',
},

# or

plug_barcode => {
    code    => sub {
        my ( $t, $q, $config ) = @_;
        return '12345678901';
    }
},

Mandatory. Takes either a string or a subref as a value. If the value is a subref, it will be called and its value will be assigned to code as if it was already there. The @_ of the subref will contain (in this order): ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object.

Specifies the code for the barcode to generate. Valid values depend on the type of the barcode you're generating. If value is an invalid barcode, plugin will error out (see ERROR HANDLING section below). If value is either undef or an empty string, plugin will stop further processing (no exit()s)

file

plug_barcode => {
    code    => '12345678901',
    file    => 'bar.png',
},

Optional. Takes a string that represents the name of the file (relative to index.pl) into which to save the image. When is not defined (or set to an empty string) the plugin will print out the right Content-type header and output the image right into the browser and then will call exit() UNLESS an error occured . Plugin will NOT call exit() if saving to the file. By default is not specified (output barcode image directly to the browser).

type

plug_barcode => {
    code    => '12345678901',
    type    => 'UPCA',
},

# or
plug_barcode => {
    code    => '12345678901',
    type    => sub {
        my ( $t, $q, $config ) = @_;
        return 'UPCA';
    },
},

Optional. Takes a string or a subref as a value. If the value is a subref, it will be called and its value will be assigned to type as if it was already there. The @_ of the subref will contain (in this order): ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object.

Represents the type of barcode to generate. See GD::Barcode distribution for possible types. As of this writing these are currently available types:

COOP2of5
Code39
EAN13
EAN8
IATA2of5
ITF
Industrial2of5
Matrix2of5
NW7
QRcode
UPCA
UPCE

If value is either undef or an empty string, plugin will stop further processing (no exit()s) Defaults to: UPCA

format

plug_barcode => {
    code    => '12345678901',
    format  => 'png',
},

Optional. Can be set to either string png or gif (case sensitive). Specifies the format of the image to generate (png is for PNG images and gif is for GIF images). Defaults to: png

no_text

plug_barcode => {
    code    => '12345678901',
    no_text => 0,
},

Optional. Takes either true or false values. When set to a true value, the plugin will not generate text (i.e. it will only make the barcode lines) in the output image. Defaults to: 0

height

plug_barcode => {
    code    => '12345678901',
    height  => 50,
},

Optional. Takes positive integer numbers as a value. Specifies the height of the generated barcode image. Defaults to: 50

ERROR HANDLING

<tmpl_if name='plug_barcode_error'>
    <p>Error: <tmpl_var escape='html' name='plug_barcode_error'></p>
</tmpl_if>

In an error occurs while generating the barcode (i.e. wrong code length was specified or some I/O error occured if saving to a file), the plugin will set the $t->{t}{plug_barcode_error} (where $t is ZofCMS Template hashref) to the error message.

SEE ALSO

GD::Barcode

AUTHOR

'Zoffix, <'zoffix at cpan.org'> (http://haslayout.net/, http://zoffix.com/, http://zofdesign.com/)

BUGS

Please report any bugs or feature requests to bug-app-zofcms-plugin-barcode at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-Barcode. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc App::ZofCMS::Plugin::Barcode

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009 'Zoffix, all rights reserved.

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