Christian Morel > Printer-Label-Template-Processor-1.0 > Printer::Label::Template::Processor

Download:
Printer-Label-Template-Processor-1.0.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.0   Source   Latest Release: Printer-Label-Template-Processor-1.01

NAME ^

Printer::Label::Template::Processor Template-based label management

SYNOPSIS ^

    # prints to standard output
    my $print_con = Printer::Label::Template::Processor->new(
        script_file   => "MyPath/MyFile.tt2",
        check_syntax  => \&my_check_sub,
        print_mode    => "CON",
    );
    $print_con or croak "Erreur lors de la création de l'imprimante";
    $print_con->printout(
        vars => {
            my_var_1 => 'My var 1',
            my_var_2 => $my_var_2,
            my_var_3 => ['My', 'var', '3'],
        }
    );

    # prints to FTP server
    my $print_ftp = Printer::Label::Template::Processor->new(
        script_file   => "MyPath/MyFile.tt2",
        check_syntax  => \&my_check_sub,
        print_mode    => "FTP",
        server        => "MyPrintServer",
    );
    $print_ftp or croak "Erreur lors de la création de l'imprimante";
    $print_ftp->printout(
        vars => {
            my_var_1 => 'My var 1',
            my_var_2 => $my_var_2,
            my_var_3 => ['My', 'var', '3'],
        }
    );

    # prints to LPR queue
    my $print_lpr = Printer::Label::Template::Processor->new(
        script_file   => "MyPath/MyFile.tt2",
        check_syntax  => \&my_check_sub,
        print_mode    => "LPR",
        server        => "MyPrintServer",
    );
    $print_lpr or croak "Erreur lors de la création de l'imprimante";
    $print_lpr->printout(
        vars => {
            my_var_1 => 'My var 1',
            my_var_2 => $my_var_2,
            my_var_3 => ['My', 'var', '3'],
        }
    );

    # prints to file
    my $print_file = Printer::Label::Template::Processor->new(
        script_file   => "MyPath/MyFile.tt2",
        check_syntax  => \&my_check_sub,
        print_mode    => "FILE",
        output_file   => "MyPath/MyFile.txt",
    );
    $print_file or croak "Erreur lors de la création de l'imprimante";
    $print_file->printout(
        vars => {
            my_var_1 => 'My var 1',
            my_var_2 => $my_var_2,
            my_var_3 => ['My', 'var', '3'],
        }
    );

(...)

    sub my_check_sub {
        my $output_data = shift;

        # checks for the presence of some commands
        return ($output_data =~ /^MyStartCommand(.*\s)*MyStopCommand$/);
    }

DESCRIPTION ^

This module provides a way to build any type of labels using templates and output them on a printing device.

A template file consists of a script written in a scripting language. Support is provided for the following scripting languages: * Perl * Template Toolkit

The template is run and passed variables through a hash. This variables are used by the script to populate fields and perform operations throughout the content of the label. The scripts returns the ready-to-print content of the label. The syntax of the output data is checked in accordance with the language used by the printing device. Once validated, the output data is sent to the printing device.

Support is provided for the following printing protocols: * CON: prints to the standard output * FTP: prints to an FTP server * LPR: prints to an LPR queue * FILE: prints to a file

CONSTANTS ^

$H_TEMPLATES

Lookup table used to link file extensions and _build_output_from_* methods.

METHODS ^

Public Methods

new

    my $print_lpr = Printer::Label::Template::Processor->new(
        script_file  => "MyPath/MyScriptFile.tt2",      # full path to the script file
        check_syntax => \&my_check_sub,                 # reference to the sub that will check the syntax of the data output by the script
        print_mode   => "LPR",                          # identifier of the printing prtotocol
        server       => "MyPrintServer",                # Identifier of the printing device (Network name, IP address...)
        port         => 555,                            # TCP port number if required
        user         => 'MyUser',                       # username if authentification is required
        password     => 'MyPassword',                   # password if authentification is required
        output_file  => "MyPath/MyOutputFile.txt"       # full path to the output file required by the FILE printing protocol
    );

Creates a label processor object. Each parameter passed to the method is set to an object's property of the same name.

printout

    $print_lpr->printout(
        vars => {
            my_var_1 => 'My var 1',
            my_var_2 => $my_var_2,
            my_var_3 => ['My', 'var', '3'],
        }
    );

Builds the output data and sends it to a printing system. The vars structure is transmitted to the template script which will use them in order to produce the content of the label. The variables can be used to fill placeholders values or any algorithmic needs.

Private Methods

_set_output_data

Builds the output data of the label. This method uses the lookup table defined in $H_TEMPLATES to identify the language of the template script. It then builds dynamically the name of the corresponding method and calls it.

_build_output_from_perl

Builds output data by processing a Perl script. Loads the Perl script, eval-s it and stores its output in the output_data property of the label object.

_build_output_from_tkit

Builds output data by processing a Template Toolkit script. Loads the Template Toolkit script, processes it and stores its output in the output_data property of the label object.

_print_to_con

Sends the content to the standard output.

_print_to_ftp

Sends the content to a FTP server.

_print_to_lpr

Sends the content to a print queue.

_print_to_file

Writes the content to a file.

AUTHOR ^

Christian Morel, <christian.morel at etat.ge.ch>, Jan. 2013

syntax highlighting: