PYX::Parser - PYX parser with callbacks.
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);
new
my $obj = PYX::Parser->new(%parameters);
Constructor.
callbacks
Callbacks.
attribute
Attribute callback. Default value is undef.
comment
Comment callback. Default value is undef.
data
Data callback. Default value is undef.
end_element
End of element callback. Default value is undef.
final
Final callback. Default value is undef.
init
Init callback. Default value is undef.
instruction
Instruction callback. Default value is undef.
rewrite
Rewrite callback. Callback is used on every line. Default value is undef.
start_element
Start of element callback. Default value is undef.
other
Other Callback. Default value is undef.
input_encoding
Input encoding for parse_file() and parse_handler() usage. Default value is 'utf-8'.
non_parser_options
Non parser options. Default value is blank reference to hash.
output_encoding
Output encoding. Default value is 'utf-8'.
output_handler
Output handler. Default value is \*STDOUT.
output_rewrite
Output 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'.
$out
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'.
$input_file
parse_handler
$obj->parse_handle($input_file_handler, $out);
Parse PYX handler. $input_file_handler handler is decoded by 'input_encoding'. If $out not present, use 'output_handler'.
$input_file_handler
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.
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; }
Class::Utils, Encode, Error::Pure, Readonly.
Install the PYX modules.
https://github.com/michal-josef-spacek/PYX
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2005-2023 Michal Josef Špaček
BSD 2-Clause License
0.09
To install PYX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PYX
CPAN shell
perl -MCPAN -e shell install PYX
For more information on module installation, please visit the detailed CPAN module installation guide.