NAME
PYX::Parser - PYX parser with callbacks.
SYNOPSIS
use PYX::Parser;
my $obj = PYX::Parser->new(%parameters);
my $line = $obj->line;
$obj->parse($pyx, $out);
$obj->parse_file($input_file, $out);
$obj->parse_handler($input_file_handler, $out);
METHODS
new
my $obj = PYX::Parser->new(%parameters);
Constructor.
callbacksCallbacks.attributeAttribute callback. Default value is undef.commentComment callback. Default value is undef.dataData callback. Default value is undef.end_elementEnd of element callback. Default value is undef.finalFinal callback. Default value is undef.initInit callback. Default value is undef.instructionInstruction callback. Default value is undef.rewriteRewrite callback. Callback is used on every line. Default value is undef.start_elementStart of element callback. Default value is undef.otherOther Callback. Default value is undef.
input_encodingInput encoding for parse_file() and parse_handler() usage. Default value is 'utf-8'.non_parser_optionsNon parser options. Default value is blank reference to hash.output_encodingOutput encoding. Default value is 'utf-8'.output_handlerOutput handler. Default value is \*STDOUT.output_rewriteOutput rewrite. Default value is 0.
line
my $line = $obj->line;
Get actual parsing line.
Returns string.
parse
$obj->parse($pyx, $out);
Parse PYX text or array of PYX text. If $out not present, use 'output_handler'.
Returns undef.
parse_file
$obj->parse_file($input_file, $out);
Parse file with PYX data. $input_file file is decoded by 'input_encoding'. If $out not present, use 'output_handler'.
Returns undef.
parse_handler
$obj->parse_handler($input_file_handler, $out);
Parse PYX handler. $input_file_handler handler is decoded by 'input_encoding'. If $out not present, use 'output_handler'.
Returns undef.
ERRORS
new():
Bad output handler.
From Class::Utils::set_params():
Unknown parameter '%s'.
parse():
Bad PYX line '%s'.
parse_file():
Bad PYX line '%s'.
No input handler.
parse_handler():
Bad PYX line '%s'.
No input handler.
EXAMPLE
use strict;
use warnings;
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(
'callbacks' => {
'start_element' => \&start_element,
'end_element' => \&end_element,
},
);
$parser->parse_handler($file_handler);
# Close file.
if ($file) {
close(INF);
}
# Start element callback.
sub start_element {
my ($self, $elem) = @_;
print "Start of element '$elem'.\n";
return;
}
# End element callback.
sub end_element {
my ($self, $elem) = @_;
print "End of element '$elem'.\n";
return;
}
DEPENDENCIES
Class::Utils, Encode, Error::Pure, Readonly.
SEE ALSO
- Task::PYX
-
Install the PYX modules.
REPOSITORY
https://github.com/michal-josef-spacek/PYX
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2005-2023 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.10