Mercurial > pub > Impl
comparison Lib/IMPL/DOM/XMLReader.pm @ 37:c2e7f7c96bcd
performance improvements, DOM reworked (a little)
author | Sergey |
---|---|
date | Mon, 23 Nov 2009 00:59:06 +0300 |
parents | 65a7bb156fb7 |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
36:1828103371d0 | 37:c2e7f7c96bcd |
---|---|
10 __PACKAGE__->PassThroughArgs; | 10 __PACKAGE__->PassThroughArgs; |
11 | 11 |
12 BEGIN { | 12 BEGIN { |
13 public _direct property Navigator => prop_get | owner_set; | 13 public _direct property Navigator => prop_get | owner_set; |
14 private _direct property _current => prop_all; | 14 private _direct property _current => prop_all; |
15 private _direct property _text => prop_all; | |
16 private _direct property _textHistory => prop_all; | |
15 } | 17 } |
16 | 18 |
17 sub Parse { | 19 sub Parse { |
18 my ($this,$in) = @_; | 20 my ($this,$in) = @_; |
19 | 21 |
31 sub ParseFile { | 33 sub ParseFile { |
32 my ($this,$in) = @_; | 34 my ($this,$in) = @_; |
33 | 35 |
34 my $parser = new XML::Parser( | 36 my $parser = new XML::Parser( |
35 Handlers => { | 37 Handlers => { |
36 Start => sub {shift; goto &_OnStart($this,@_)}, | 38 Start => sub {shift; unshift @_, $this; goto &_OnBegin;}, |
37 End => sub {shift; goto &_OnEnd($this,@_)}, | 39 End => sub {shift; unshift @_, $this; goto &_OnEnd;}, |
38 Char => sub {shift; goto &_OnChar($this,@_)} | 40 Char => sub {shift; unshift @_, $this; goto &_OnChar;} |
39 } | 41 } |
40 ); | 42 ); |
41 | 43 |
42 $parser->parsefile($in); | 44 $parser->parsefile($in); |
43 } | 45 } |
44 | 46 |
45 | 47 |
46 sub _OnBegin { | 48 sub _OnBegin { |
47 my ($this,$element,%attrs) = @_; | 49 my ($this,$element,%attrs) = @_; |
48 | 50 |
51 push @{$this->{$_textHistory}},$this->{$_text}; | |
52 $this->{$_text} = ""; | |
49 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs); | 53 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs); |
50 } | 54 } |
51 | 55 |
52 sub _OnEnd { | 56 sub _OnEnd { |
53 my ($this,$element) = @_; | 57 my ($this,$element) = @_; |
54 | 58 |
55 $this->{$_current} = $this->Back; | 59 $this->{$_current}->nodeValue($this->{$_text}) if length $this->{$_text}; |
60 $this->{$_text} = pop @{$this->{$_textHistory}}; | |
61 $this->{$_current} = $this->Navigator->Back; | |
56 } | 62 } |
57 | 63 |
58 sub _OnChar { | 64 sub _OnChar { |
59 my ($this,$val) = @_; | 65 my ($this,$val) = @_; |
60 | 66 $this->{$_text} .= $val; |
61 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val); | |
62 } | 67 } |
63 | 68 |
64 1; | 69 1; |
65 | 70 |
66 __END__ | 71 __END__ |