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.attributeAttribute handler. Default value is undef.commentComment handler. Default value is undef.dataData handler. Default value is undef.end_tagEnd of tag handler. Default value is undef.finalFinal handler. Default value is undef.initInit handler. Default value is undef.instructionInstruction handler. Default value is undef.start_tagStart of tag handler. Default value is undef.output_rewriteOutput rewrite. Default value is 0.output_handlerOutput handler. Default value is \*STDOUT.otherOther 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
SEE ALSO
AUTHOR
Michal Špaček skim@cpan.org.
LICENSE AND COPYRIGHT
BSD 2-Clause License
VERSION
0.01