# HG changeset patch # User sergey # Date 1382514556 -14400 # Node ID 8001dc056331c3785a615cbbbe484a32b61aa650 # Parent ae61af01bfa514ad07eb742a579e17f3939f7d8d fixed problems with sax parser fixed handling of empty repos added log autoflush diff -r ae61af01bfa5 -r 8001dc056331 _test/repo.pl --- a/_test/repo.pl Wed Oct 23 01:13:19 2013 +0400 +++ b/_test/repo.pl Wed Oct 23 11:49:16 2013 +0400 @@ -23,6 +23,11 @@ name => 'nvidia', dir => 'nvidia', location => 'ftp://download.nvidia.com/opensuse/12.3/' + }, + { + name => 'broken', + dir => 'broken', + location => 'http://mirror.yandex.ru/opensuse/repositories/KDE:/Extra/KDE_Release_410_openSUSE_12.3/' } ); diff -r ae61af01bfa5 -r 8001dc056331 _test/test_xml.pl --- a/_test/test_xml.pl Wed Oct 23 01:13:19 2013 +0400 +++ b/_test/test_xml.pl Wed Oct 23 11:49:16 2013 +0400 @@ -2,16 +2,20 @@ package MyParser; use IMPL::declare { + require => { + XMLReader => 'XML::LibXML::Reader' + }, base => [ 'Yours::Parsers::SaxParser' => undef ] }; + sub ProcessRootNode { my ($this,$node) = @_; my $handler; - my $level = 0; + my $level = 1; $handler = sub { my ($me,$node) = @_; print ' ' x $level, $node->depth, " ", $node->name,"\n"; @@ -25,16 +29,27 @@ } my $text = ' - - + + + asd - + '; -MyParser->new()->Parse({ +my $reader = XMLReader->new({ string => $text }); +while ($reader->read) { + print " " x $reader->depth, "[", $reader->nodeType,"] ", $reader->name, "\n" +} + +print "\n"; + +MyParser->new()->Parse({ + string => $text +}); + diff -r ae61af01bfa5 -r 8001dc056331 lib/Yours/Parsers/PMDParser.pm --- a/lib/Yours/Parsers/PMDParser.pm Wed Oct 23 01:13:19 2013 +0400 +++ b/lib/Yours/Parsers/PMDParser.pm Wed Oct 23 11:49:16 2013 +0400 @@ -22,6 +22,9 @@ $this->ReadChildren(sub { my ($me,$reader) = @_; + + return unless $reader->localName eq 'package'; + my $type = $me->attribute('type'); my $package = $me->ReadComplexNode({ diff -r ae61af01bfa5 -r 8001dc056331 lib/Yours/Parsers/SaxParser.pm --- a/lib/Yours/Parsers/SaxParser.pm Wed Oct 23 01:13:19 2013 +0400 +++ b/lib/Yours/Parsers/SaxParser.pm Wed Oct 23 11:49:16 2013 +0400 @@ -21,9 +21,9 @@ my $reader = $this->_reader( XMLReader->new($options) ); - $reader->read(); - $this->ProcessRootNode($reader); - $reader->read(); + if ( $reader->read() > 0) { + $this->ProcessRootNode($reader); + } } sub ProcessRootNode { @@ -34,19 +34,18 @@ my ( $this, $handler ) = @_; my $reader = $this->_reader; - - return if $reader->isEmptyElement; - - my $currentLevel = $reader->depth+1; - - while ( - $reader->read - ) - { - print "---\n" and return if $reader->depth <= $currentLevel && $reader->nodeType == XML_READER_TYPE_END_ELEMENT; - #if ($reader->nodeType != XML_READER_TYPE_END_ELEMENT) { - $this->$handler($reader) if $handler; - #} + + # содержимое можеть быть только у не пустых элементов + if($reader->nodeType == XML_READER_TYPE_ELEMENT && !$reader->isEmptyElement) { + # нужно прочитать все, что ниже, для этого запоминаем текущий уровень + my $currentLevel = $reader->depth; + + # при чтении и проверке данного условия "съедается" закрывающий теэг текущего узла + while($reader->read && $reader->depth > $currentLevel) { + # при обходе дочерних узлов нужно пропустить закрывающие узлы + $this->$handler($reader) + if $handler and $reader->nodeType != XML_READER_TYPE_END_ELEMENT; + } } } diff -r ae61af01bfa5 -r 8001dc056331 lib/Yours/SyncRepository.pm --- a/lib/Yours/SyncRepository.pm Wed Oct 23 01:13:19 2013 +0400 +++ b/lib/Yours/SyncRepository.pm Wed Oct 23 11:49:16 2013 +0400 @@ -181,6 +181,7 @@ if (my $h = $this->log) { printf $h ($format,@args); print $h "\n"; + $h->flush; } }