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_handle($input_file_handler, $out);
METHODS
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. Default value is 'utf-8'.non_parser_optionsNon parser options. Default value is blank reference to hash.output_rewriteOutput rewrite. Default value is 0.output_handlerOutput handler. Default value is \*STDOUT.
line()-
Get actual parsing line. Returns string. 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():
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
# 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(
'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/tupinek/PYX
AUTHOR
Michal Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2005-2016 Michal Špaček
BSD 2-Clause License
VERSION
0.05