| 1 | package PYX::Sort; | ||
| 2 | |||
| 3 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 6 | ▶ | use Class::Utils qw(set_params); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 6 | ▶ | use PYX::Parser; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 6 | our $VERSION = 0.05; | |
| 10 | |||
| 11 | # Constructor. | ||
| 12 | 6 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 13 | 6 | my ($class, @params) = @_; | |
| 14 | 6 | my $self = bless {}, $class; | |
| 15 | |||
| 16 | # Output handler. | ||
| 17 | 6 | $self->{'output_handler'} = \*STDOUT; | |
| 18 | |||
| 19 | # Process params. | ||
| 20 | 6 | set_params($self, @params); | |
| 21 | |||
| 22 | # PYX::Parser object. | ||
| 23 | $self->{'pyx_parser'} = PYX::Parser->new( | ||
| 24 | 'callbacks' => { | ||
| 25 | 'attribute' => \&_attribute, | ||
| 26 | 'start_element' => \&_tag, | ||
| 27 | 'end_element' => \&_tag, | ||
| 28 | 'comment' => \&_tag, | ||
| 29 | 'instruction' => \&_tag, | ||
| 30 | 'data' => \&_tag, | ||
| 31 | }, | ||
| 32 | 'non_parser_options' => { | ||
| 33 | 'tag' => {}, | ||
| 34 | }, | ||
| 35 | 4 | 'output_handler' => $self->{'output_handler'}, | |
| 36 | ); | ||
| 37 | |||
| 38 | # Object. | ||
| 39 | 4 | return $self; | |
| 40 | } | ||
| 41 | |||
| 42 | # Parse pyx text or array of pyx text. | ||
| 43 | 2 | ▶ | sub parse { |
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||
| 44 | 2 | my ($self, $pyx, $out) = @_; | |
| 45 | 2 | $self->{'pyx_parser'}->parse($pyx, $out); | |
| 46 | 2 | return; | |
| 47 | } | ||
| 48 | |||
| 49 | # Parse file with pyx text. | ||
| 50 | 2 | ▶ | sub parse_file { |
|
Subroutine
parse_file: called CC=1 SCAR=0.0
Pod
documented
| |||
| 51 | 2 | my ($self, $file, $out) = @_; | |
| 52 | 2 | $self->{'pyx_parser'}->parse_file($file, $out); | |
| 53 | 2 | return; | |
| 54 | } | ||
| 55 | |||
| 56 | # Parse from handler. | ||
| 57 | 2 | ▶ | sub parse_handler { |
|
Subroutine
parse_handler: called CC=1 SCAR=0.0
Pod
documented
| |||
| 58 | 2 | my ($self, $input_file_handler, $out) = @_; | |
| 59 | 2 | $self->{'pyx_parser'}->parse_handler($input_file_handler, $out); | |
| 60 | 2 | return; | |
| 61 | } | ||
| 62 | |||
| 63 | # Process attribute. | ||
| 64 | 18 | ▶ | sub _attribute { |
|
Subroutine
_attribute: called CC=1 SCAR=0.0
| |||
| 65 | 18 | my ($pyx_parser_obj, $att, $attval) = @_; | |
| 66 | 18 | $pyx_parser_obj->{'non_parser_options'}->{'tag'}->{$att} = $attval; | |
| 67 | 18 | return; | |
| 68 | } | ||
| 69 | |||
| 70 | # Process tag. | ||
| 71 | 18 | ▶ | sub _tag { |
|
Subroutine
_tag: called CC=1 SCAR=0.0
| |||
| 72 | 18 | my $pyx_parser_obj = shift; | |
| 73 | 18 | my $out = $pyx_parser_obj->{'output_handler'}; | |
| 74 | 18 | _flush($pyx_parser_obj); | |
| 75 | 18 | print {$out} $pyx_parser_obj->line, "\n"; | |
| 76 | 18 | return; | |
| 77 | } | ||
| 78 | |||
| 79 | # Flush attributes. | ||
| 80 | 18 | ▶ | sub _flush { |
|
Subroutine
_flush: called CC=2 SCAR=6.9
| |||
| 81 | 18 | my $pyx_parser_obj = shift; | |
| 82 | 18 | my $out = $pyx_parser_obj->{'output_handler'}; | |
| 83 | 18 | foreach my $key (sort keys %{$pyx_parser_obj->{'non_parser_options'} | |
| 84 | 18 | ->{'tag'}}) { | |
| 85 | |||
| 86 | 18 | print {$out} 'A'.$key.'="'.$pyx_parser_obj | |
| 87 | 18 | ->{'non_parser_options'}->{'tag'}->{$key}.'"'."\n"; | |
| 88 | } | ||
| 89 | 18 | $pyx_parser_obj->{'non_parser_options'}->{'tag'} = {}; | |
| 90 | 18 | return; | |
| 91 | } | ||
| 92 | |||
| 93 | 6 | 1; | |
| 94 | |||
| 95 | __END__ | ||