/[suikacvs]/messaging/manakai/lib/Message/Util/ManakaiNode.dis
Suika

Contents of /messaging/manakai/lib/Message/Util/ManakaiNode.dis

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Sat Sep 24 11:57:25 2005 UTC (19 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.18: +98 -53 lines
++ manakai/bin/ChangeLog	24 Sep 2005 10:49:30 -0000
	(dac_load_module_file): Allow "|" as qname prefix separator.
++ manakai/lib/Message/Markup/ChangeLog	24 Sep 2005 11:11:32 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* SuikaWikiConfig21.dis: Use "disPerl:H" instead
	of "disPerl:Q" for hash keys.
	(expandQName): Removed the "g" option from the "s///",
	which was very serious and difficult bug.

++ manakai/lib/Message/Util/ChangeLog	24 Sep 2005 11:01:40 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* ManakaiNode.dis (mn:node, mn:nodeID, mn:treeID): New
	properties.
	(mn:stemName, mn:refName): New properties.

	* Makefile (.discore-all.pm): New rule to create dis-related
	Perl module files at once.

	* DIS.dis (PERL_HASH_KEY_ALREADY_DEFINED_ERR): New error code.
	(hashKeyName, hashKeyScope, anotherURI): New error parameters.

	* ManakaiNode.dis, DIS.dis, PerlCode.dis: Use "disPerl:H" instead
	of "disPerl:Q" for hash keys.

++ manakai/lib/Message/Util/Error/ChangeLog	24 Sep 2005 10:58:31 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* ManakaiNode.dis: Use "disPerl:H" instead
	of "disPerl:Q" for hash keys.

++ manakai/lib/Message/Util/DIS/ChangeLog	24 Sep 2005 11:06:19 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* Perl.dis (plCodeFragment): Takes hash key name
	from the database for "mn:node" and "DOMCore:read-only",
	where they were hardcoded.  For GetProp and SetProp
	dis tree element instructions, hash key name
	is shorten if shorter version is defined by "DISPerl:propHashKey"
	property of the corresponding resource in the database.
	(plAddHashKey): New method to check hash key name dupulication.
	(dp:plHashKey): New property.

	* Perl.dis, DNLite.dis, DISDoc.dis, DISDump.dis:
	Use "disPerl:H" instead of "disPerl:Q" for hash keys.

++ manakai/lib/Message/DOM/ChangeLog	24 Sep 2005 10:55:11 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* DOMMain.dis (MDOM:): Reintroduced for "ManakaiDOM:ManakaiDOM1"
	and "ManakaiDOM:ManakaiDOM2".

	* DOMFeature.dis, DOMMain.dis, DOMCore.dis, DOMXML.dis,
	DOMLS.dis, SimpleLS.dis, GenericLS.dis: Use disPerl:H
	instead of disPerl:Q for internal property hash keys.

	* DOMFeature.dis, DOMCore.dis, DOMXML.dis: Missing property
	definitions added.

	* DOMCore.dis (DOMCore:TextNode, DOMCore:DocumentFragmentNode):
	New resources.

	* DOMXML.dis (DOMXML:EntityNode, DOMXML:EntityReferenceNode): New
	resources.

++ manakai/lib/manakai/ChangeLog	24 Sep 2005 11:08:14 -0000
2005-09-24  Wakaba  <wakaba@suika.fam.cx>

	* XML.dis: The "DISPerl:propHashKey" property
	added to properties.  Now the module depends on the DISPerl
	module.

	* DISPerl.dis (DISPerl:propHashKey): New property.

1 wakaba 1.1 Module:
2     @QName:
3     Util:ManakaiNode
4     @FullName:
5     @@lang: en
6     @@@:
7     Manakai Generic Node Implementation
8     @Namespace:
9     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ManakaiNode#
10    
11     @Description:
12     @@lang:en
13     @@@:
14     The <Module::Util:ManakaiNode> module provides a basic
15     implementation for glaph (perhaps tree) structures.
16    
17 wakaba 1.18 @DISCore:author: DISCore|Wakaba
18 wakaba 1.1 @License:
19     license:Perl+MPL
20     @Date:
21     @@@:
22 wakaba 1.19 $Date: 2005/09/23 18:25:05 $
23 wakaba 1.1 @@ContentType:
24     dis:Date.RCS
25    
26     @Require:
27     @@Module:
28 wakaba 1.4 @@@QName:
29     DISlib:DISPerl
30 wakaba 1.1 @@@WithFor:
31     ManakaiDOM:all
32 wakaba 1.2 @@Module:
33 wakaba 1.16 @@@QName: Util|ManakaiNode
34 wakaba 1.2 @@@WithFor:
35     ManakaiDOM:Perl
36    
37     @DefaultFor:
38     ManakaiDOM:Perl
39 wakaba 1.1
40     Namespace:
41 wakaba 1.13 @DIS:
42     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#
43 wakaba 1.1 @dis:
44     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--
45     @dis2pm:
46     http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm#
47 wakaba 1.4 @DISlib:
48     http://suika.fam.cx/~wakaba/archive/2004/dis/
49 wakaba 1.13 @doc:
50     http://suika.fam.cx/~wakaba/archive/2005/7/tutorial#
51 wakaba 1.1 @lang:
52     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#
53     @license:
54     http://suika.fam.cx/~wakaba/archive/2004/8/18/license#
55     @ManakaiDOM:
56     http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#
57 wakaba 1.10 @mn:
58     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ManakaiNode#
59 wakaba 1.1 @Perl:
60     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl--
61     @rdf:
62     http://www.w3.org/1999/02/22-rdf-syntax-ns#
63     @rdfs:
64     http://www.w3.org/2000/01/rdf-schema#
65     @TreeCore:\
66     @Util:
67     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/
68    
69     ResourceDef:
70     @QName:
71     Util:
72     @rdf:type:
73     dis:ModuleGroup
74     @FullName:
75     @@lang:en
76     @@@:
77     The manakai support modules
78 wakaba 1.17 @DISPerl:packageName:
79 wakaba 1.14 Message::Util::
80 wakaba 1.17 @DISPerl:interfacePackageName:
81     Message::Util::IF::
82 wakaba 1.13
83 wakaba 1.1 ## -- Internal node object
84    
85     ClassDef:
86 wakaba 1.10 @resourceFor: ForFull
87     @resourceFor: ForCompact
88     @resourceFor:
89     ManakaiDOM:ForIF
90    
91     @QName:
92     @@@: NodeStem
93     @@ForCheck:
94     ManakaiDOM:ForIF
95    
96 wakaba 1.1 @QName:
97 wakaba 1.10 @@@:
98     ManakaiDOM:ManakaiDOMNodeObject
99     @@ForCheck: ForFull
100    
101     @QName:
102     @@@: ManakaiNodeStem
103     @@ForCheck: ForCompact
104    
105     @Implement:
106     @@@: NodeStem
107     @@ForCheck: ForFull
108    
109     @Implement:
110     @@@: NodeStem
111     @@ForCheck: ForCompact
112    
113 wakaba 1.1 @Description:
114     @@lang:en
115     @@@:
116     Internal (actual) node objects that is accessed via
117     <Class::ManakaiDOM:ManakaiDOMNodeReference> objects referring it.
118     @ImplNote:
119     @@lang:en
120     @@@:
121     No public interface should be defined for any class inheriting
122     this class - applications should access to nodes only via
123     <Class::ManakaiDOM:ManakaiDOMNodeReference> objects.
124     @ImplNote:
125 wakaba 1.13 @@ForCheck: ManakaiDOM|ForClass
126 wakaba 1.1 @@lang:en
127     @@@:
128 wakaba 1.13 A <Class::> object is a blessed hash
129 wakaba 1.1 reference. Each hash key and value pair is called as a
130     <DFN::property>. Currently, several core properties
131 wakaba 1.13 are defined as listed below. Applications of this class,
132     such as <Class::DOMCore:ManakaiDOMNode::ManakaiDOM:all>,
133     defines additional properties for their own purpose and scope.
134 wakaba 1.1 \
135 wakaba 1.13 {doc:fig:: <doc:caption::Core node properties>
136    
137     {doc:figBody::
138 wakaba 1.1 \
139     - <CODE::TreeCore:nodeID>::: The global-unique identifier for
140     this node object.
141     \
142     - <CODE::TreeCore:treeID>::: The global-unique identifier for the
143     tree containing this node object.
144     \
145     - <CODE::TreeCore:rc>::: The number that denotes how many reference
146     to this node there are.
147     \
148     - <CODE::TreeCore:origin>::: An array reference, containing
149     hash key names of <DFN::origin>
150     properties for this node.
151     \
152 wakaba 1.3 - <CODE::TreeCore:subnode0>::: An array reference, containing
153     hash key names of <DFN::subnode>
154     properties for this node.
155     \
156 wakaba 1.1 - <CODE::TreeCore:subnode>::: An array reference, containing
157 wakaba 1.3 hash key names of <DFN::subnode> list
158 wakaba 1.1 properties for this node.
159     \
160     - <CODE::TreeCore:subnode2>::: An array reference, containing
161 wakaba 1.3 hash key names of <DFN::subnode> (two steps) list
162 wakaba 1.1 properties for this node.
163     \
164     - <CODE::TreeCore:irefnode>::: An array reference, containing
165     hash key names of <DFN::irefnode>
166     properties for this node.
167     \
168     - <CODE::TreeCore:anydata>::: An array reference, containing
169 wakaba 1.3 hash key names of <DFN::anydata> list
170     properties for this node.
171 wakaba 1.1 \
172     - <CODE::TreeCore:anydata2>::: An array reference, containing
173 wakaba 1.3 hash key names of <DFN::anydata> (two steps) list properties
174 wakaba 1.1 for this node.
175 wakaba 1.13 }
176 wakaba 1.1 }
177    
178     @IntMethod:
179     @@Name: new
180     @@Description:
181     @@@lang:en
182     @@@@:
183     Constructs a new instance of
184     <Class::ManakaiDOM:ManakaiDOMNodeObject> and returns it.
185     @@Return:
186 wakaba 1.10 @@@Type: NodeStem
187 wakaba 1.1 @@@Description:
188     @@@@lang:en
189     @@@@@:
190     The newly created <Class::ManakaiDOM:ManakaiDOMNodeObject> instance.
191 wakaba 1.7 @@@PerlDef:
192 wakaba 1.1 $r = bless {
193     <Q::TreeCore:origin> => [],
194 wakaba 1.3 <Q::TreeCore:subnode0> => [],
195 wakaba 1.1 <Q::TreeCore:subnode> => [],
196     <Q::TreeCore:subnode2> => [],
197     <Q::TreeCore:irefnode> => [],
198     <Q::TreeCore:anydata> => [],
199     <Q::TreeCore:anydata2> => [],
200 wakaba 1.19 <H::mn:rc> => 0,
201     <H::mn:treeID> => <Code::ManakaiDOM:generateUniqueID>,
202     <H::mn:nodeID> => <Code::ManakaiDOM:generateUniqueID>,
203 wakaba 1.1 }, ref $self || $self;
204 wakaba 1.10
205 wakaba 1.1 @IntMethod:
206     @@Name: newReference
207     @@Description:
208     @@@lang:en
209     @@@@:
210     Creates a new reference to this node and returns it.
211 wakaba 1.6 @@DISCore:isDeprecated:
212     @@@@:1
213     @@@DISCore:alt: getNewReference
214 wakaba 1.10 @@ForCheck: ForFull
215 wakaba 1.1 @@Param:
216     @@@Name: class
217     @@@Type:
218 wakaba 1.7 Perl:package-name::ManakaiDOM:all
219 wakaba 1.1 @@@Description:
220     @@@@lang:en
221     @@@@@:
222     A Perl class package name with which the newly created
223     reference is blessed. The <P::class> class must be a
224     subclass of <Class::ManakaiDOM:ManakaiDOM:ManakaiDOMNodeReference>.
225     @@Return:
226     @@@Type:
227     ManakaiDOM:ManakaiDOMNodeReference
228     @@@Description:
229     @@@@lang:en
230     @@@@@:
231     The newly created node reference.
232     @@@PerlDef:
233     $r = bless {
234 wakaba 1.19 <H::mn:node> => $self,
235 wakaba 1.7 }, ref $class ? ref $class : defined $class ? $class :
236 wakaba 1.1 <ClassName::ManakaiDOM:ManakaiDOMNodeReference>;
237 wakaba 1.19 $self->{<H::mn:rc>}++;
238 wakaba 1.6
239     @ResourceDef:
240     @@QName: getNewReference
241     @@rdf:type:
242     dis2pm:BlockCode
243 wakaba 1.10 @@ForCheck: ForFull
244 wakaba 1.6 @@Description:
245     @@@lang:en
246     @@@@:
247     Creates a new node reference object.
248     @@ResourceDef:
249     @@@rdf:type:
250     DISPerl:CodeParameter
251     @@@Name: $object
252 wakaba 1.10 @@@Type: NodeStem
253 wakaba 1.6 @@@In:1
254     @@@enDesc:
255     A node object for which a reference is created.
256     @@@DISPerl:paramStyle: var
257     @@ResourceDef:
258     @@@rdf:type:
259     DISPerl:CodeParameter
260     @@@Name: $ref
261 wakaba 1.10 @@@Type: NodeRef
262 wakaba 1.6 @@@Out:1
263     @@@enDesc:
264     A node reference for <P::$object>. It may or may not
265     be same as <P::$object>.
266     @@@DISPerl:paramStyle: var
267     @@ResourceDef:
268     @@@rdf:type:
269     DISPerl:CodeParameter
270     @@@Name: $class
271     @@@Type:
272     Perl:package-name::ManakaiDOM:all
273     @@@enDesc:
274     A package name with which <P::$ref> is blessed.
275     @@@In:1
276     @@@DISPerl:paramStyle: any
277     @@PerlDef:
278 wakaba 1.19 $object->{<H::mn:rc>}++;
279 wakaba 1.6 $ref = bless {
280 wakaba 1.19 <H::mn:node> => $object,
281 wakaba 1.6 }, $class;
282    
283     @ResourceDef:
284     @@QName: getWeakReference
285     @@rdf:type:
286     dis2pm:BlockCode
287 wakaba 1.10 @@ForCheck: ForFull
288 wakaba 1.6 @@Description:
289     @@@lang:en
290     @@@@:
291     Creates a new weak node reference object.
292     \
293     The weak node reference is actually a node reference
294     except that this code fragment does not increment
295     the reference count of the object. When all non-weak
296     references to the object are destructed, then
297     the object is destructed and any operation via
298     weak references will lead unexpected result.
299     \
300     {NOTE:: It is intended that internal code creates a weak reference
301     so that it gets access to public interface.
302     \
303     }
304     @@ResourceDef:
305     @@@rdf:type:
306     DISPerl:CodeParameter
307     @@@Name: $object
308 wakaba 1.10 @@@Type: NodeStem
309 wakaba 1.6 @@@In:1
310     @@@enDesc:
311     A node object for which a reference is created.
312     @@@DISPerl:paramStyle: var
313     @@ResourceDef:
314     @@@rdf:type:
315     DISPerl:CodeParameter
316     @@@Name: $ref
317 wakaba 1.10 @@@Type: NodeRef
318 wakaba 1.6 @@@Out:1
319     @@@enDesc:
320     A node reference for <P::$object>. It may or may not
321     be same as <P::$object>.
322     @@@DISPerl:paramStyle: var
323     @@ResourceDef:
324     @@@rdf:type:
325     DISPerl:CodeParameter
326     @@@Name: $class
327     @@@Type:
328     Perl:package-name::ManakaiDOM:all
329     @@@enDesc:
330     A package name with which <P::$ref> is blessed.
331     @@@In:1
332     @@@DISPerl:paramStyle: any
333     @@PerlDef:
334     $ref = bless {
335 wakaba 1.19 <H::mn:node> => $object,
336     <H::mn:isWeak> => true,
337 wakaba 1.8 }, $class;
338    
339     @ResourceDef:
340     @@QName: getWeakRef
341     @@rdf:type:
342     dis2pm:InlineCode
343 wakaba 1.10 @@ForCheck: ForFull
344 wakaba 1.8 @@Description:
345     @@@lang:en
346     @@@@:
347     Creates a new weak node reference object.
348     \
349     The weak node reference is actually a node reference
350     except that this code fragment does not increment
351     the reference count of the object. When all non-weak
352     references to the object are destructed, then
353     the object is destructed and any operation via
354     weak references will lead unexpected result.
355     \
356     {NOTE:: It is intended that internal code creates a weak reference
357     so that it gets access to public interface.
358     \
359     }
360     @@ResourceDef:
361     @@@rdf:type:
362     DISPerl:CodeParameter
363     @@@Name: $object
364 wakaba 1.10 @@@Type: NodeStem
365 wakaba 1.8 @@@In:1
366     @@@enDesc:
367     A node object for which a reference is created.
368     @@@DISPerl:paramStyle: var
369     @@ResourceDef:
370     @@@rdf:type:
371     DISPerl:CodeParameter
372     @@@Name: $class
373     @@@Type:
374     Perl:package-name::ManakaiDOM:all
375     @@@enDesc:
376     A package name with which <P::$ref> is blessed.
377     @@@In:1
378     @@@DISPerl:paramStyle: any
379     @@PerlDef:
380 wakaba 1.9 (bless {
381 wakaba 1.19 <H::mn:node> => $object,
382     <H::mn:isWeak> => true,
383 wakaba 1.9 }, $class)
384 wakaba 1.6
385 wakaba 1.1 @IntMethod:
386     @@Name: isExternallyReferred
387     @@Description:
388     @@@lang:en
389     @@@@:
390     Checks whether the tree containing this node has been referred
391     from the outside of the tree or not.
392     @@Return:
393     @@@Type:
394 wakaba 1.7 DISPerl:Boolean::ManakaiDOM:all
395 wakaba 1.1 @@@InCase:
396 wakaba 1.15 @@@@Value:
397     @@@@@@:1
398     @@@@@ContentType: DISCore|Boolean
399 wakaba 1.1 @@@@Description:
400     @@@@@lang:en
401     @@@@@@:
402     There is one or more nodes in the tree that has been
403     referred via <Class::ManakaiDOM:ManakaiDOMNodeReference> objects.
404     @@@InCase:
405 wakaba 1.15 @@@@Value:
406     @@@@@@:0
407     @@@@@ContentType: DISCore|Boolean
408 wakaba 1.1 @@@@Description:
409     @@@@@lang:en
410     @@@@@@: No external reference found.
411     @@@PerlDef:
412 wakaba 1.10 @@@@ForCheck: ForFull
413     @@@@@:
414 wakaba 1.19 if ($self->{<H::mn:rc>}) {
415 wakaba 1.1 $r = true;
416     } else {
417     my @node = ($self);
418     my %checked;
419 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
420 wakaba 1.9 next unless UNIVERSAL::isa ($node,
421     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
422 wakaba 1.19 if ($node->{<H::mn:rc>}) {
423 wakaba 1.1 $r = true;
424     last NODES;
425 wakaba 1.19 } elsif ($checked{$node->{<H::mn:nodeID>}}) {
426 wakaba 1.1 next NODES;
427     }
428     my @n;
429 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
430     if (ref $node->{$p} eq 'ARRAY') {
431     push @n, @{$node->{$p}};
432     } elsif (ref $node->{$p} eq 'HASH') {
433     push @n, values %{$node->{$p}};
434 wakaba 1.1 }
435     }
436 wakaba 1.3 for my $p (@n,
437     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
438     if (ref $p eq 'ARRAY') {
439     push @node, @$p;
440     } elsif (ref $p eq 'HASH') {
441     push @node, values %$p;
442 wakaba 1.1 }
443     }
444 wakaba 1.6 for my $p (@{$node->{<Q::TreeCore:origin>}}) {
445     unshift @node, $node->{$p} if $node->{$p};
446     ## NOTE: Puts the top of the list,
447     ## since upper-level nodes are expected to be referred
448     ## more than lower-levels.
449     }
450     for my $p (@{$node->{<Q::TreeCore:subnode0>}}) {
451 wakaba 1.3 push @node, $node->{$p} if $node->{$p};
452 wakaba 1.1 }
453 wakaba 1.19 $checked{$node->{<H::mn:nodeID>}} = true;
454 wakaba 1.1 }
455     }
456 wakaba 1.10 @@@PerlDef:
457     @@@@ForCheck: ForCompact
458     @@@@@:
459 wakaba 1.19 if ($self->{<H::mn:rc>}) {
460 wakaba 1.10 $r = true;
461     } else {
462     my @node = ($self);
463     my %checked;
464 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
465 wakaba 1.10 next unless ref $node;
466 wakaba 1.19 if ($node->{<H::mn:rc>}) {
467 wakaba 1.10 $r = true;
468     last NODES;
469 wakaba 1.19 } elsif ($checked{$node->{<H::mn:nodeID>}}) {
470 wakaba 1.10 next NODES;
471     }
472     my @n;
473     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
474     if (ref $node->{$p} eq 'ARRAY') {
475     push @n, @{$node->{$p}};
476     } elsif (ref $node->{$p} eq 'HASH') {
477     push @n, values %{$node->{$p}};
478     }
479     }
480     for my $p (@n,
481     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
482     if (ref $p eq 'ARRAY') {
483     push @node, @$p;
484     } elsif (ref $p eq 'HASH') {
485     push @node, values %$p;
486     }
487     }
488     for my $p (@{$node->{<Q::TreeCore:origin>}}) {
489     unshift @node, $node->{$p} if $node->{$p};
490     ## NOTE: Puts the top of the list,
491     ## since upper-level nodes are expected to be referred
492     ## more than lower-levels.
493     }
494     for my $p (@{$node->{<Q::TreeCore:subnode0>}}) {
495     push @node, $node->{$p} if $node->{$p};
496     }
497 wakaba 1.19 $checked{$node->{<H::mn:nodeID>}} = 1;
498 wakaba 1.10 }
499     }
500 wakaba 1.1
501     @IntMethod:
502     @@Name: destroy
503     @@Description:
504     @@@lang:en
505     @@@@:
506     Destructs the tree containing this node.
507     @@Return:
508     @@@PerlDef:
509 wakaba 1.10 @@@@ForCheck: ForFull
510     @@@@@:
511 wakaba 1.1 my @node = ($self);
512 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
513 wakaba 1.1 my @n;
514 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
515     if (ref $node->{$p} eq 'ARRAY') {
516     push @n, @{$node->{$p}};
517     } elsif (ref $node->{$p} eq 'HASH') {
518     push @n, values %{$node->{$p}};
519 wakaba 1.1 }
520     }
521 wakaba 1.3 for my $p (@n,
522     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
523     if (ref $p eq 'ARRAY') {
524 wakaba 1.10 push @node, grep {UNIVERSAL::isa ($_,
525     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
526 wakaba 1.19 and defined $_->{<H::mn:nodeID>}} @$p;
527 wakaba 1.3 } elsif (ref $p eq 'HASH') {
528 wakaba 1.10 push @node, grep {UNIVERSAL::isa ($_,
529     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
530 wakaba 1.19 and defined $_->{<H::mn:nodeID>}}
531 wakaba 1.3 values %$p;
532 wakaba 1.1 }
533     }
534 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
535     \ @{$node->{<Q::TreeCore:subnode0>}}) {
536     push @node, $node->{$p}
537     if defined $node->{$p} and
538 wakaba 1.19 defined $node->{$p}->{<H::mn:nodeID>};
539 wakaba 1.1 }
540     %$node = ();
541     }
542 wakaba 1.10 @@@PerlDef:
543     @@@@ForCheck: ForCompact
544     @@@@@:
545     my @node = ($self);
546 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
547 wakaba 1.19 next unless ref $node and defined $node->{<H::mn:nodeID>};
548 wakaba 1.10 my @n;
549     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
550     if (ref $node->{$p} eq 'ARRAY') {
551     push @n, @{$node->{$p}};
552     } elsif (ref $node->{$p} eq 'HASH') {
553     push @n, values %{$node->{$p}};
554     }
555     }
556     for my $p (@n,
557     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
558     if (ref $p eq 'ARRAY') {
559     push @node, @$p;
560     } elsif (ref $p eq 'HASH') {
561     push @node, values %$p;
562     }
563     }
564     for my $p (@{$node->{<Q::TreeCore:origin>}},
565     \ @{$node->{<Q::TreeCore:subnode0>}}) {
566     push @node, $node->{$p};
567     }
568     %$node = ();
569     }
570 wakaba 1.1 @@ImplNote:
571     @@@lang:en
572     @@@@:
573     This method is different from Perl <Perl::DESTROY> special
574     purpose method.
575     \
576     An <QUOTE::uninitialized> warning in this method might mean
577     some method puts an <Perl::undef> into a list of nodes.
578    
579     @IntMethod:
580     @@Name: importTree
581     @@Description:
582     @@@lang:en
583     @@@@:
584     Changes the tree identifier of the nodes belong to another tree
585     to be same as this node's tree identifier.
586     @@Param:
587     @@@Name: node
588     @@@Type:
589     ManakaiDOM:ManakaiDOMNodeObject
590     @@@Description:
591     @@@@lang:en
592     @@@@@:
593     Any node from the tree to change its identifier.
594     @@Return:
595     @@@PerlDef:
596 wakaba 1.10 @@@@ForCheck: ForFull
597     @@@@@:
598 wakaba 1.19 unless ($node->{<H::mn:treeID>} eq
599     $self->{<H::mn:treeID>}) {
600 wakaba 1.1 my @node = ($node);
601 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
602 wakaba 1.10 next unless UNIVERSAL::isa ($node,
603     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
604 wakaba 1.1 my @n;
605 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
606     if (ref $node->{$p} eq 'ARRAY') {
607     push @n, @{$node->{$p}};
608     } elsif (ref $node->{$p} eq 'HASH') {
609     push @n, values %{$node->{$p}};
610 wakaba 1.1 }
611     }
612 wakaba 1.3 for my $p (@n,
613     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
614     if (ref $p eq 'ARRAY') {
615 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
616     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
617 wakaba 1.19 and $_->{<H::mn:treeID>} ne
618     $self->{<H::mn:treeID>}} @$p;
619 wakaba 1.3 } elsif (ref $p eq 'HASH') {
620 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
621     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
622 wakaba 1.19 and $_->{<H::mn:treeID>} ne
623     $self->{<H::mn:treeID>}}
624 wakaba 1.3 values %$p;
625 wakaba 1.1 }
626     }
627 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
628     \ @{$node->{<Q::TreeCore:subnode0>}}) {
629     push @node, $node->{$p}
630     if defined $node->{$p} and
631 wakaba 1.19 $node->{$p}->{<H::mn:treeID>} ne
632     $self->{<H::mn:treeID>};
633 wakaba 1.1 }
634 wakaba 1.19 $node->{<H::mn:treeID>} = $self->{<H::mn:treeID>};
635 wakaba 1.1 }
636     }
637 wakaba 1.10 @@@PerlDef:
638     @@@@ForCheck: ForCompact
639     @@@@@:
640     my @node = ($node);
641 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
642 wakaba 1.10 next unless ref $node;
643 wakaba 1.19 next if $node->{<H::mn:treeID>} eq
644     $self->{<H::mn:treeID>};
645 wakaba 1.10 my @n;
646     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
647     if (ref $node->{$p} eq 'ARRAY') {
648     push @n, @{$node->{$p}};
649     } elsif (ref $node->{$p} eq 'HASH') {
650     push @n, values %{$node->{$p}};
651     }
652     }
653     for my $p (@n,
654     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
655     if (ref $p eq 'ARRAY') {
656     push @node, @$p;
657     } elsif (ref $p eq 'HASH') {
658     push @node, values %$p;
659     }
660     }
661     for my $p (@{$node->{<Q::TreeCore:origin>}},
662     \ @{$node->{<Q::TreeCore:subnode0>}}) {
663     push @node, $node->{$p};
664     }
665 wakaba 1.19 $node->{<H::mn:treeID>} = $self->{<H::mn:treeID>};
666 wakaba 1.10 }
667 wakaba 1.1
668     @IntMethod:
669     @@Name: changeTreeID
670     @@Description:
671     @@@lang:en
672     @@@@:
673     Changes tree identifier of all nodes traversable from this node.
674     @@Param:
675     @@@Name: treeID
676     @@@Type:
677 wakaba 1.7 DISPerl:String::ManakaiDOM:all
678 wakaba 1.1 @@@Description:
679     @@@@lang:en
680     @@@@@:
681     The new tree identifier.
682     @@Return:
683     @@@PerlDef:
684 wakaba 1.10 @@@@ForCheck: ForFull
685     @@@@@:
686 wakaba 1.19 unless ($self->{<H::mn:treeID>} eq $treeID) {
687 wakaba 1.1 my @node = ($self);
688 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
689 wakaba 1.9 next unless UNIVERSAL::isa ($node,
690     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
691 wakaba 1.1 my @n;
692 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
693     if (ref $node->{$p} eq 'ARRAY') {
694     push @n, @{$node->{$p}};
695     } elsif (ref $node->{$p} eq 'HASH') {
696     push @n, values %{$node->{$p}};
697 wakaba 1.1 }
698     }
699 wakaba 1.3 for my $p (@n,
700     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
701     if (ref $p eq 'ARRAY') {
702 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
703     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
704 wakaba 1.5 and
705 wakaba 1.19 $_->{<H::mn:treeID>} ne $treeID} @$p;
706 wakaba 1.3 } elsif (ref $p eq 'HASH') {
707 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
708     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
709 wakaba 1.19 and $_->{<H::mn:treeID>} ne $treeID}
710 wakaba 1.3 values %$p;
711 wakaba 1.1 }
712     }
713 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
714     \ @{$node->{<Q::TreeCore:subnode0>}}) {
715     push @node, $node->{$p}
716     if defined $node->{$p} and
717 wakaba 1.19 $node->{$p}->{<H::mn:treeID>} ne $treeID;
718 wakaba 1.1 }
719 wakaba 1.19 $node->{<H::mn:treeID>} = $treeID;
720 wakaba 1.1 }
721     }
722     @@@PerlDef:
723 wakaba 1.10 @@@@ForCheck: ForCompact
724     @@@@@:
725     my @node = ($self);
726 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
727 wakaba 1.10 next unless ref $node;
728 wakaba 1.19 next if $node->{<H::mn:treeID>} eq $treeID;
729 wakaba 1.10 my @n;
730     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
731     if (ref $node->{$p} eq 'ARRAY') {
732     push @n, @{$node->{$p}};
733     } elsif (ref $node->{$p} eq 'HASH') {
734     push @n, values %{$node->{$p}};
735     }
736     }
737     for my $p (@n,
738     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
739     if (ref $p eq 'ARRAY') {
740     push @node, @$p;
741     } elsif (ref $p eq 'HASH') {
742     push @node, values %$p;
743     }
744     }
745     for my $p (@{$node->{<Q::TreeCore:origin>}},
746     \ @{$node->{<Q::TreeCore:subnode0>}}) {
747     push @node, $node->{$p};
748     }
749 wakaba 1.19 $node->{<H::mn:treeID>} = $treeID;
750 wakaba 1.1 }
751    
752     @IntMethod:
753     @@Name: isSameNode
754     @@Description:
755     @@@lang:en
756     @@@@:
757     Returns whether a node is the same as this node or not.
758     \
759     {NOTE:: The sameness is different from the equality;
760     two nodes are same iff they are same hash reference.
761     \
762     }
763     @@Operator:
764     @@@ContentType:
765     lang:Perl
766     @@@@: eq
767     @@Param:
768     @@@Name: node
769 wakaba 1.10 @@@Type: NodeStem
770 wakaba 1.1 @@@Description:
771     @@@@lang:en
772     @@@@@:
773     A node to compare with.
774     @@Return:
775     @@@Type:
776 wakaba 1.7 DISPerl:Boolean::ManakaiDOM:all
777 wakaba 1.1 @@@Description:
778     @@@@lang:en
779     @@@@@: Whether the two nodes are same or not.
780     @@@PerlDef:
781 wakaba 1.10 @@@@ForCheck: ForFull
782     @@@@@:
783 wakaba 1.1 if (ref $node and
784     UNIVERSAL::isa ($node,
785     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>) and
786 wakaba 1.19 $node->{<H::mn:nodeID>} eq $self->{<H::mn:nodeID>}) {
787 wakaba 1.1 $r = true;
788     }
789 wakaba 1.10 @@@PerlDef:
790     @@@@ForCheck: ForCompact
791     @@@@@:
792     if (ref $node and
793     UNIVERSAL::isa ($node, <ClassName::NodeStem>) and
794 wakaba 1.19 $node->{<H::mn:nodeID>} eq $self->{<H::mn:nodeID>}) {
795 wakaba 1.10 $r = true;
796     }
797 wakaba 1.1 @IntMethod:
798     @@Name: orphanate
799     @@Description:
800     @@@lang:en
801     @@@@:
802     Notifies that this node (and its neibors if any) is no longer
803     part of the main tree. If the new tree containing this node
804     has been referred yet, then the tree is preserved except its
805     tree identifier has changed. Otherwise, i.e. the tree is
806     useless any more, then it is destructed.
807     \
808     {NOTE:: Interaction on deleting a relationship from multiply
809     organized <QUOTE::trees> (such as DOM tree and
810     styled displaying tree) is less studied. This
811     method might be modified or addition of another method(s)
812     might be required when style sheet, XBL, or other
813     technologies has been implemented.
814     \
815     }
816     @@Return:
817     @@@PerlDef:
818 wakaba 1.10 if ($self-><M::NodeStem.isExternallyReferred>) {
819     $self-><M::NodeStem.changeTreeID>
820     (<Code::ManakaiDOM:generateUniqueID>);
821 wakaba 1.1 } else {
822 wakaba 1.10 $self-><M::NodeStem.destroy>;
823 wakaba 1.1 }
824 wakaba 1.10 ##NodeStem
825 wakaba 1.1
826     ## -- Public node object
827    
828     ClassDef:
829 wakaba 1.10 @resourceFor: ForFull
830     @resourceFor: ForCompact
831     @resourceFor:
832     ManakaiDOM:ForIF
833    
834     @QName:
835     @@@: NodeRef
836     @@ForCheck:
837     ManakaiDOM:ForIF
838    
839 wakaba 1.1 @QName:
840 wakaba 1.10 @@@:
841     ManakaiDOM:ManakaiDOMNodeReference
842     @@ForCheck: ForFull
843    
844     @Implement:
845     @@@: NodeRef
846     @@ForCheck: ForFull
847    
848     @QName:
849     @@@: ManakaiNodeRef
850     @@ForCheck: ForCompact
851    
852     @Implement:
853     @@@: NodeRef
854     @@ForCheck: ForCompact
855    
856 wakaba 1.1 @Description:
857     @@lang:en
858     @@@:
859     References to the node object corresponding to it. From
860     applications' view, any node object is hidden and
861     <Class::ManakaiDOM:ManakaiDOMNodeReference> seems as if
862     the node itself.
863     @ImplNote:
864     @@lang:en
865     @@@:
866 wakaba 1.13 {P:: A <Class::ManakaiDOM:ManakaiDOMNodeReference> is a blessed hash
867 wakaba 1.1 reference; currently there is a hash key defined:
868     \
869     - <CODE::TreeCore:node>::: A node object
870     (<Class::ManakaiDOM:ManakaiDOMNodeObject>) to which
871     this is referring.
872 wakaba 1.13
873     - <CODE::TreeCore:isWeak>::: Whether the reference is <QUOTE::weak>
874     or not.
875     }
876    
877     @ResourceDef:
878     @@Name: free
879     @@rdf:type: DISLang|Method
880     @@enDesc:
881     Frees the grove referenced by this object. Once
882     this operation is done, results of operations to objects belonging
883     to the grove are unknown.
884     @@ForCheck: ForCompact
885     @@Return:
886     @@@PerlDef:
887 wakaba 1.19 $self->{<H::mn:node>}-><M::NodeStem.destroy>;
888 wakaba 1.1
889     @IntMethod:
890     @@Name: destroy
891     @@Description:
892     @@@lang:en
893     @@@@: Destroy this reference object.
894     @@Operator:
895     @@@ContentType:
896     lang:Perl
897     @@@@: DESTROY
898     @@Return:
899     @@@PerlDef:
900     @@@@@:
901 wakaba 1.19 my $node = $self->{<H::mn:node>};
902 wakaba 1.1 if ($node) {
903 wakaba 1.19 CORE::delete $self->{<H::mn:node>};
904     unless ($self->{<H::mn:isWeak>}) {
905     $node->{<H::mn:rc>}--;
906 wakaba 1.10 unless ($node-><M::NodeStem.isExternallyReferred>) {
907     $node-><M::NodeStem.destroy>;
908 wakaba 1.6 }
909 wakaba 1.1 }
910     } else {
911     warn ref ($self) . q{->DESTROY: there is no associated }.
912     q{node object - you have a global variable or }.
913     qq{potential memory-leak detected\n};
914     }
915     @@@@ImplNote:
916     @@@@@lang:en
917     @@@@@@:
918     {P::Warning during the global destruction might mean:
919     \
920     - there be a loop in the manakai internal implementation -
921     it should be a bug.
922     \
923     - there be a loop created by application, e.g.
924     event handler containing a reference to any node
925     belonging to the same tree.
926     \
927     - there be a global variable that contains a node reference
928     and it is not altered or <Perl::undef>ed until the global
929     destruction.
930     \
931     - or other unknown bad situation.
932     \
933     }
934     @@ImplNote:
935     @@@lang:en
936     @@@@:
937     Don't override this method unintentionally - for example,
938     inheritting <PerlModule::Tie::Array> would hide this method
939     from that class, since that module defines its own
940     destructor.
941 wakaba 1.10 ##NodeRef
942 wakaba 1.6
943     PropDef:
944 wakaba 1.19 @QName: mn|nodeID
945     @enDesc:
946     The globally unique identifier of the node.
947     @mn:stemName: nid
948    
949     PropDef:
950     @QName: mn|treeID
951     @enDesc:
952     The globally unique identifier of the grove to which the
953     node belongs.
954     @mn:stemName: tid
955    
956     PropDef:
957     @QName: mn|rc
958     @enDesc:
959     The number of the reference that points the node.
960     @mn:stemName: rc
961    
962     PropDef:
963     @QName: mn|node
964     @mn:refName: node
965     @rdfs:domain: mn|NodeRef||ManakaiDOM|Perl
966     @rdfs:range: mn|NodeStem||ManakaiDOM|Perl
967    
968     PropDef:
969     @QName: mn|isWeak
970 wakaba 1.6 @enDesc:
971     Whether a reference is weak or not.
972 wakaba 1.19 @rdfs:domain: mn|NodeRef||ManakaiDOM|Perl
973 wakaba 1.16 @Type: DISPerl|Boolean
974 wakaba 1.19 @mn:refName: w
975    
976     PropDef:
977     @QName: mn|stemName
978     @enDesc:
979     The key name of the property when it is used in <Class::ManakaiNodeStem
980     ::ManakaiDOM:Perl>.
981     @dataType: DISCore|String
982     @multipleProperties: DISCore|Single
983     @rdfs:domain: rdfs|Property
984     @rdfs:subPropertyOf: DISPerl|propHashKey
985    
986     PropDef:
987     @QName: mn|refName
988     @enDesc:
989     The key name of the property when it is used in <Class::ManakaiNodeRef
990     ::ManakaiDOM:Perl>.
991     @dataType: DISCore|String
992     @multipleProperties: DISCore|Single
993     @rdfs:domain: rdfs|Property
994     @rdfs:subPropertyOf: DISPerl|propHashKey
995 wakaba 1.6
996     ElementTypeBinding:
997     @Name:PropDef
998     @ElementType:
999     dis:ResourceDef
1000     @ShadowContent:
1001     @@rdf:type:
1002     rdf:Property
1003 wakaba 1.16 @@For: =ManakaiDOM|all
1004 wakaba 1.6
1005     ElementTypeBinding:
1006     @Name:enDesc
1007     @ElementType:
1008     dis:Description
1009     @ShadowContent:
1010     @@lang:en
1011 wakaba 1.1
1012     ## -- Frequently used code fragments
1013    
1014     ResourceDef:
1015     @QName:
1016     ManakaiDOM:generateUniqueID
1017     @rdf:type:
1018     dis2pm:InlineCode
1019     @Description:
1020     @@lang:en
1021     @@@:
1022     Generates a global-unique opaque string.
1023     \
1024     {NOTE:: A URI reference is generated by this code.
1025     \
1026     }
1027 wakaba 1.16
1028     @For: =ManakaiDOM|Perl
1029    
1030 wakaba 1.1 @PerlDef:
1031     (
1032     sprintf 'mid:%d.%d.%s.dom.manakai@suika.fam.cx#',
1033     time, $$,
1034     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1035     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1036     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1037     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1038     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62]
1039     )
1040     ##ManakaiDOM:generateUniqueID
1041    
1042     ## -- lang:dis vocabulary
1043    
1044     TreeElementType:
1045     @QName:
1046     dis:GetProp
1047     @dataType:
1048     dis:TypeQName
1049     @rdfs:range:
1050     rdf:Property
1051     @Description:
1052     @@lang:en
1053     @@@:
1054     Gets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference>
1055     property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property).
1056    
1057     TreeElementType:
1058     @QName:
1059     dis:SetProp
1060     @dataType:
1061     dis:TypeQName
1062     @rdfs:range:
1063     rdf:Property
1064     @Description:
1065     @@lang:en
1066     @@@:
1067     Sets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference>
1068     property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property).
1069    
1070     ## -- Syntax sugar
1071    
1072     ElementTypeBinding:
1073     @Name: TreeElementType
1074     @ElementType:
1075     dis:ResourceDef
1076     @ShadowContent:
1077     @@rdf:type:
1078     DISLang:TreeElementType
1079 wakaba 1.16 @@For: =ManakaiDOM|all
1080 wakaba 1.1
1081     ElementTypeBinding:
1082     @Name: ClassDef
1083     @ElementType:
1084     dis:ResourceDef
1085     @ShadowContent:
1086     @@rdf:type:
1087     @@@@:
1088 wakaba 1.10 dis:MultipleResource
1089     @@@ForCheck:
1090     !ForFull !ForCompact !ManakaiDOM:ForIF
1091     @@rdf:type:
1092     @@@@:
1093     ManakaiDOM:IF
1094     @@@ForCheck:
1095     ManakaiDOM:ForIF
1096     @@rdf:type:
1097     @@@@:
1098     ManakaiDOM:Class
1099     @@@ForCheck: ForFull
1100     @@rdf:type:
1101     @@@@:
1102     ManakaiDOM:Class
1103     @@@ForCheck: ForCompact
1104 wakaba 1.2 @@ForCheck:
1105     ManakaiDOM:Perl
1106 wakaba 1.10
1107     ForDef:
1108     @QName:
1109     mn:ForFull
1110     @ISA:
1111     ManakaiDOM:ForClass
1112    
1113     ForDef:
1114     @QName:
1115     mn:ForCompact
1116     @ISA:
1117     ManakaiDOM:ForClass
1118 wakaba 1.1
1119     ElementTypeBinding:
1120     @Name: IntMethod
1121     @ElementType:
1122     dis:ResourceDef
1123     @ShadowContent:
1124     @@rdf:type:
1125     DISLang:Method
1126     @@ManakaiDOM:isForInternal:1
1127    
1128     ElementTypeBinding:
1129     @Name: Return
1130     @ElementType:
1131     dis:ResourceDef
1132     @ShadowContent:
1133     @@rdf:type:
1134     DISLang:MethodReturn
1135    
1136     ElementTypeBinding:
1137     @Name: Param
1138     @ElementType:
1139     dis:ResourceDef
1140     @ShadowContent:
1141     @@rdf:type:
1142     DISLang:MethodParameter
1143    
1144     ElementTypeBinding:
1145     @Name: PerlDef
1146     @ElementType:
1147     dis:Def
1148     @ShadowContent:
1149     @@ContentType:
1150     lang:Perl
1151    
1152     ElementTypeBinding:
1153     @Name: InCase
1154     @ElementType:
1155     dis:ResourceDef
1156     @ShadowContent:
1157     @@rdf:type:
1158     ManakaiDOM:InCase

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24