The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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.
  • 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.
     Default value is 'utf-8'.
  • non_parser_options

     Non parser options.
     Default value is blank reference to hash.
  • output_rewrite

     Output rewrite.
     Default value is 0.
  • output_handler

     Output 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

http://skim.cz

LICENSE AND COPYRIGHT

 © 2005-2016 Michal Špaček
 BSD 2-Clause License

VERSION

0.05