| 1 | #!/usr/bin/env perl | ||
| 2 | # XML::Axk::SAX::Handler - Process an XML file using SAX. | ||
| 3 | # Copyright (c) 2018 cxw42. All rights reserved. Artistic 2. | ||
| 4 | # I am using SAX rather than XML::LibXML::Reader because I want full control | ||
| 5 | # over the DOM document throughout the processing. | ||
| 6 | |||
| 7 | package XML::Axk::SAX::Handler; | ||
| 8 | 2 | ▶ | use XML::Axk::Base; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use XML::Axk::DOM; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | use parent 'XML::Axk::SAX::BuildDOM2'; | ||
| 12 | # General strategy: when encountering an element, call SUPER, then process. | ||
| 13 | # When leaving an element, process, call SUPER, then remove the node we just | ||
| 14 | # left from the DOM to keep the memory consumption down. | ||
| 15 | |||
| 16 | sub new | ||
| 17 | { | ||
| 18 | my ($class, $core, @args) = @_; | ||
| 19 | croak "Need an XML::Axk::Core" unless ref $core eq "XML::Axk::Core"; | ||
| 20 | |||
| 21 | my $self = $class->SUPER::new(@args); | ||
| 22 | $self->{axkcore} = $core; | ||
| 23 | return $self; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub work { | ||
| 27 | my ($self, $now) = @_; | ||
| 28 | $self->{axkcore}->_run_worklist( | ||
| 29 | $now, | ||
| 30 | # The new core parameters (CPs) | ||
| 31 | document => $self->{Document}, | ||
| 32 | record => $self->{Element} | ||
| 33 | ); | ||
| 34 | } | ||
| 35 | |||
| 36 | # Handlers ============================================================== {{{1 | ||
| 37 | |||
| 38 | sub start_document { | ||
| 39 | my $self = shift; | ||
| 40 | $self->SUPER::start_document(@_); | ||
| 41 | $self->work(HI); | ||
| 42 | } #start_document() | ||
| 43 | |||
| 44 | sub end_document { | ||
| 45 | my $self = shift; | ||
| 46 | $self->work(BYE); | ||
| 47 | $self->SUPER::end_document(@_); | ||
| 48 | } #end_document() | ||
| 49 | |||
| 50 | #sub characters { | ||
| 51 | # my $self = shift; | ||
| 52 | # $self->SUPER::characters(@_); | ||
| 53 | #} #characters() | ||
| 54 | |||
| 55 | sub start_element { | ||
| 56 | my $self = shift; | ||
| 57 | $self->SUPER::start_element(@_); | ||
| 58 | $self->work(HI); | ||
| 59 | } #start_element() | ||
| 60 | |||
| 61 | sub end_element { | ||
| 62 | my $self = shift; | ||
| 63 | $self->work(BYE); | ||
| 64 | $self->SUPER::end_element(@_); | ||
| 65 | } #end_element() | ||
| 66 | |||
| 67 | #sub entity_reference { | ||
| 68 | # my $self = shift; | ||
| 69 | # $self->SUPER::entity_reference(@_); | ||
| 70 | #} #entity_reference() | ||
| 71 | |||
| 72 | sub comment { | ||
| 73 | my $self = shift; | ||
| 74 | $self->SUPER::comment(@_); | ||
| 75 | $self->work(HI); # no BYE for comments | ||
| 76 | } #comment() | ||
| 77 | |||
| 78 | # }}}1 | ||
| 79 | # Unimplemented routines ================================================ {{{3 | ||
| 80 | # Ones we don't need to override | ||
| 81 | #start_cdata | ||
| 82 | #end_cdata | ||
| 83 | |||
| 84 | # Not doing these yet | ||
| 85 | #doctype_decl | ||
| 86 | #attlist_decl | ||
| 87 | #xml_decl | ||
| 88 | #entity_decl | ||
| 89 | #unparse_decl | ||
| 90 | #element_decl | ||
| 91 | #notation_decl | ||
| 92 | #processing_instruction | ||
| 93 | |||
| 94 | # }}}3 | ||
| 95 | 1; | ||
| 96 | __END__ | ||