NAME

PYX::Parser - PYX parser with handlers.

SYNOPSIS

use PYX::Parser; my $obj = PYX::Parser->new(%parameters); $obj->parse($pyx, $out); $obj->parse_file($input_file, $out); $obj->parse_handle($input_file_handler, $out);

METHODS

new(%parameters)
Constructor.
  • attribute

    Attribute handler.
    Default value is undef.
  • comment

    Comment handler.
    Default value is undef.
  • data

    Data handler.
    Default value is undef.
  • end_tag

    End of tag handler.
    Default value is undef.
  • final

    Final handler.
    Default value is undef.
  • init

    Init handler.
    Default value is undef.
  • instruction

    Instruction handler.
    Default value is undef.
  • start_tag

    Start of tag handler.
    Default value is undef.
  • output_rewrite

    Output rewrite.
    Default value is 0.
  • output_handler

    Output handler.
    Default value is \*STDOUT.
  • other

    Other handler.
    Default value is undef.
parse($pyx[, $out])
Parse PYX text or array of PYX text.
If $out not present, use 'output_handler'.
Returns undef.
parse_file($input_file[, $out])
Parse file with PYX data.
If $out not present, use 'output_handler'.
Returns undef.
parse_handler($input_file_handler[, $out])
Parse PYX handler.
If $out not present, use 'output_handler'.
Returns undef.

ERRORS

new():
        From Class::Utils::set_params():
                Unknown parameter '%s'.

parse():
        Bad PYX tag at line '%s'.

parse_file():
        Bad PYX tag at line '%s'.
        No input handler.

parse_handler():
        Bad PYX tag at line '%s'.
        No input handler.

EXAMPLE

# Pragmas.
use strict;
use warnings;

# Modules.
use PYX::Parser;

# Open file.
my $file_handler = \*STDIN;
my $file = $ARGV[0];
if ($file) {
       if (! open(INF, '<', $file)) {
               die "Cannot open file '$file'.";
       }
       $file_handler = \*INF;
}

# PYX::Parser object.
my $parser = PYX::Parser->new(
       'start_tag' => \&start_tag,
       'end_tag' => \&end_tag,
);
$parser->parse_handler($file_handler);

# Close file.
if ($file) {
       close(INF);
}

# Start tag handler.
sub start_tag {
       my ($self, $tag) = @_;
       print "Start of tag '$tag'.\n";
}

# End tag handler.
sub end_tag {
       my ($self, $tag) = @_;
       print "End of tag '$tag'.\n";
}

DEPENDENCIES

Class::Utils, Error::Pure.

SEE ALSO

PYX, PYX::Utils.

AUTHOR

Michal Špaček skim@cpan.org.

LICENSE AND COPYRIGHT

BSD 2-Clause License

VERSION

0.01