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 argumeants
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 documeantation 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 occurred, 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 argumeants
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
},

# set config with a sub
plug_barcode => sub {
    my ( $t, $q, $config ) = @_;
}

Mandatory. Specifies plugin's options. Takes a hashref or a subref as a value. If subref is specified, its return value will be assigned to plug_barcode as if it was already there. If sub returns an undef, then plugin will stop further processing. The @_ of the subref will contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and App::ZofCMS::Config object. Possible keys/values of the hashref 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 occurred . 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 occurred 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

REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS

BUGS

To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues

If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org

AUTHOR

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

LICENSE

You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.