Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Document.pm @ 149:b04e978d6d5a
minor changes
| author | wizard |
|---|---|
| date | Wed, 18 Aug 2010 03:14:57 +0400 |
| parents | e6447ad85cb4 |
| children | 1e7f03414b65 |
| rev | line source |
|---|---|
| 49 | 1 package IMPL::DOM::Document; |
| 2 use strict; | |
| 3 use warnings; | |
| 4 | |
| 5 use base qw(IMPL::DOM::Node); | |
| 6 | |
| 7 __PACKAGE__->PassThroughArgs; | |
| 8 | |
| 9 sub document { | |
| 10 return $_[0]; | |
| 11 } | |
| 12 | |
| 13 sub Create { | |
| 14 my ($this,$nodeName,$class,$refProps) = @_; | |
| 15 | |
|
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
16 if ( ref $class eq 'HASH' ) { |
|
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
17 $refProps = $class; |
|
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
18 $class = undef; |
|
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
19 } |
|
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
20 |
|
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
21 $class ||= typeof IMPL::DOM::Node; |
| 49 | 22 $refProps ||= {}; |
| 23 | |
| 24 delete $refProps->{nodeName}; | |
| 25 | |
|
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
77
diff
changeset
|
26 die new IMPL::Exception("class is not specified") unless $class; |
| 49 | 27 return $class->new( |
| 28 nodeName => $nodeName, | |
| 29 document => $this, | |
| 30 %$refProps | |
| 31 ); | |
| 32 } | |
| 33 | |
| 34 { | |
| 35 my $empty; | |
| 36 sub Empty() { | |
| 37 return $empty ? $empty : $empty = __PACKAGE__->new(nodeName => 'Empty'); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 1; | |
| 42 __END__ | |
| 43 | |
| 44 =pod | |
| 45 | |
| 77 | 46 =head1 NAME |
| 47 | |
| 48 C<IMPL::DOM::Document> DOM документ. | |
| 49 | |
| 49 | 50 =head1 DESCRIPTION |
| 51 | |
| 77 | 52 Документ, позволяет создавать узлы определенных типов, что позволяет абстрагироваться |
| 53 от механизмов реального создания объектов. Т.о. например C<IMPL::DOM::Navigator::Builder> | |
| 54 может формировать произвольные документы. | |
| 55 | |
| 56 =head1 SYNOPSIS | |
| 57 | |
| 58 =begin code | |
| 59 | |
| 60 package MyDocument; | |
| 61 use base qw(IMPL::DOM::Document); | |
| 62 | |
| 63 sub Create { | |
| 64 my $this = shift; | |
| 65 my ($name,$class,$hashProps) = @_; | |
| 66 | |
| 67 if ($class eq 'Info') { | |
| 68 return MyInfo->new($name,$hashProps->{date},$hashProps->{description}); | |
| 69 } else { | |
| 70 # leave as it is | |
| 71 return $this->SUPER::Create(@_); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 =end code | |
| 76 | |
| 49 | 77 =head1 METHODS |
| 78 | |
| 79 =over | |
| 80 | |
| 77 | 81 =item C< Create($nodeName,$class,$hashProps) > |
| 82 | |
| 83 Реализация по умолчанию. Создает узел определеннго типа с определенным именем и свойствами. | |
| 84 | |
| 85 =begin code | |
| 49 | 86 |
| 77 | 87 sub Create { |
| 88 my ($this,$nodeName,$class,$hashProps) = @_; | |
| 89 | |
| 90 return $class->new ( | |
| 91 nodeName => $nodeName, | |
| 92 document => $this, | |
| 93 %$hashProps | |
| 94 ); | |
| 95 } | |
| 96 | |
| 97 =end code | |
| 49 | 98 |
| 99 =back | |
| 100 | |
| 101 =cut |
