annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Sergey
parents:
diff changeset
1 package IMPL::DOM::XMLReader;
Sergey
parents:
diff changeset
2 use strict;
Sergey
parents:
diff changeset
3 use warnings;
Sergey
parents:
diff changeset
4
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object IMPL::Object::Autofill);
Sergey
parents:
diff changeset
6 use IMPL::Class::Property;
Sergey
parents:
diff changeset
7 use IMPL::Class::Property::Direct;
Sergey
parents:
diff changeset
8 use XML::Parser;
Sergey
parents:
diff changeset
9
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
10 __PACKAGE__->PassThroughArgs;
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
11
10
Sergey
parents:
diff changeset
12 BEGIN {
Sergey
parents:
diff changeset
13 public _direct property Navigator => prop_get | owner_set;
Sergey
parents:
diff changeset
14 private _direct property _current => prop_all;
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
15 private _direct property _text => prop_all;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
16 private _direct property _textHistory => prop_all;
10
Sergey
parents:
diff changeset
17 }
Sergey
parents:
diff changeset
18
Sergey
parents:
diff changeset
19 sub Parse {
Sergey
parents:
diff changeset
20 my ($this,$in) = @_;
Sergey
parents:
diff changeset
21
Sergey
parents:
diff changeset
22 my $parser = new XML::Parser(
Sergey
parents:
diff changeset
23 Handlers => {
Sergey
parents:
diff changeset
24 Start => sub {shift; goto &OnStart($this,@_)},
Sergey
parents:
diff changeset
25 End => sub {shift; goto &OnEnd($this,@_)},
Sergey
parents:
diff changeset
26 Char => sub {shift; goto &OnChar($this,@_)}
Sergey
parents:
diff changeset
27 }
Sergey
parents:
diff changeset
28 );
Sergey
parents:
diff changeset
29
Sergey
parents:
diff changeset
30 $parser->parse($in);
Sergey
parents:
diff changeset
31 }
Sergey
parents:
diff changeset
32
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
33 sub ParseFile {
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
34 my ($this,$in) = @_;
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
35
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
36 my $parser = new XML::Parser(
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
37 Handlers => {
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
38 Start => sub {shift; unshift @_, $this; goto &_OnBegin;},
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
39 End => sub {shift; unshift @_, $this; goto &_OnEnd;},
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
40 Char => sub {shift; unshift @_, $this; goto &_OnChar;}
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
41 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
42 );
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
43
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
44 $parser->parsefile($in);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
45 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
46
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
47
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
48 sub _OnBegin {
10
Sergey
parents:
diff changeset
49 my ($this,$element,%attrs) = @_;
Sergey
parents:
diff changeset
50
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
51 push @{$this->{$_textHistory}},$this->{$_text};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
52 $this->{$_text} = "";
11
75980091813b DOM и навигация
Sergey
parents: 10
diff changeset
53 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
10
Sergey
parents:
diff changeset
54 }
Sergey
parents:
diff changeset
55
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
56 sub _OnEnd {
10
Sergey
parents:
diff changeset
57 my ($this,$element) = @_;
Sergey
parents:
diff changeset
58
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
59 $this->{$_current}->nodeValue($this->{$_text}) if length $this->{$_text};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
60 $this->{$_text} = pop @{$this->{$_textHistory}};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
61 $this->{$_current} = $this->Navigator->Back;
10
Sergey
parents:
diff changeset
62 }
Sergey
parents:
diff changeset
63
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
64 sub _OnChar {
10
Sergey
parents:
diff changeset
65 my ($this,$val) = @_;
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 14
diff changeset
66 $this->{$_text} .= $val;
10
Sergey
parents:
diff changeset
67 }
Sergey
parents:
diff changeset
68
Sergey
parents:
diff changeset
69 1;
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
70
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
71 __END__
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
72
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
73 =pod
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
74
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
75 =head1 SYNOPSIS
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
76
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
77 my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
78 my $obj = $reader->parsefile("data.xml");
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
79
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
80 =head1 DESCRIPTION
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
81
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
82 , .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
83 .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
84
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
85 C<NavigateCreate> C<Back>
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
86
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
87 =head1 METHODS
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
88
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
89 =over
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
90
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
91 =item C<CTOR(Naviagtor => $builder)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
92
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
93 ,
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
94
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
95 =item C<$obj->Parse($in)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
96
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
97 . xml , HANDLE.
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
98
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
99 =item C<$obj->ParseFile($fileName)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
100
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
101 C<$fileName>.
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
102
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
103 =back
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
104
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
105 =cut