Why does XML :: Twig not call my end_tag_handler?

I try to call a routine for each tag, but it end_tag_handlersnever gets called.
My goal is the sequence:

--- sequence ---
when <auto>call \&loading.
when a <apps><title>call \&kicks.
when a <apps><logs>call \&bye.
when called <apps> \&app.
when a <apps><title>call \&kicks.
when a <apps><logs>call \&bye.
when called <apps> \&app.
when </auto>call \&finish. He was not called.

temp.pl:

#!/usr/local/bin/perl -w

use XML::Twig;
my $twig = XML::Twig->new(
            start_tag_handlers => 
              { 'auto' => \&loading
              },
            twig_handlers =>
              { 'apps/title' => \&kicks,
                'apps/logs' => \&bye
              },
            twig_roots =>
              { 'apps' => \&app
              },
            end_tag_handlers => 
              { 'auto' => \&finish
              }
            );
$twig -> parsefile( "doc.xml");

  sub loading {
    print "---loading--- \n";
  }

  sub kicks {
    my ($twig, $elt) = @_;
    print "---kicks--- \n";
    print $elt -> text;
    print " \n";
  }

  sub app {
    my ($twig, $apps) = @_;
    print "---app--- \n";
    print $apps -> text;
    print " \n";
  }

  sub bye {
  my ($twig, $elt) = @_;
  print "---bye--- \n";
  print $elt->text;
  print " \n";
  }

  sub finish {
    print "---fishish--- \n";
  }

doc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<auto>
  <apps>
    <title>watch</title>
    <commands>set,start,00:00,alart,end</commands>
    <logs>csv</logs>
  </apps>
  <apps>
    <title>machine</title>
    <commands>down,select,vol_100,check,line,end</commands>
    <logs>dump</logs>
  </apps>
</auto>

exit:

C:\>perl temp.pl
---loading---
---kicks---
watch
---bye---
csv
---app---
watchset,start,00:00,alart,endcsv
---kicks---
machine
---bye---
dump
---app---
machinedown,select,vol_100,check,line,enddump  

I would like more here.

---finish---
+3
1

XML:: Twig:

end_tag_handlers

A hash { = > \& }. , , ( XML:: Parser End). 2 params: .

twig_handlers , , ? end_tag_handlers : twig_roots, .

auto, . twig_roots apps. .

, twig_handlers.

, :

my $twig = XML::Twig->new(
        start_tag_handlers => 
          { 'auto' => \&loading
          },
        twig_handlers =>
          { 'apps/title' => \&kicks,
            'apps/logs' => \&bye,
            'auto'      => \&finish
          },
        twig_roots =>
          { 'apps' => \&app
          },
        );
+6

Source: https://habr.com/ru/post/1718137/


All Articles