[MTOS-dev] More sophisticated interface of MT::Template::Node
Hirotaka Ogawa
hirotaka.ogawa at gmail.com
Sat Mar 1 11:11:07 PST 2008
Hi,
Related to weaken patch [1], I'm wondering why we cannot provide more
proper interface to MT::Template::Node class.
[1] http://code.sixapart.com/trac/movabletype/changeset/1427
Because MT::Template::Node has neither a constructor nor sufficient
accessors, we need to specify which references are weak, at every
constructions of NODE object and every updates of weak-referenced
fields of NODE. It is also not good, as for readability and
maintainability. Who knows $node->[2]->[0]->[2]->[0] means the first
child of the first child of $node?
Attached patch is for making up for such drawbacks and includes
following changes:
(1) Modifying NODE representation
Basically, a NODE is represented by an array which includes a tag
name, an attribute hash, a node value, an array of child nodes, and so
on. But, when a node is a 'TEXT', its content (nodeValue) is stored
to the 2nd element of the array, on the other hand, when not a 'TEXT',
its nodeValue is stored to 4th element.
After applying this patch, the content (nodeValue) is always stored to
4th element of the NODE array.
(2) Adding a constructor and accessors
For MT::Template::Node class, new(), tag(), attributes(), and
attribute_list() methods are added as a constructor and accessors, and
template() and nodeValue() are modified. These methods properly
handle weak references and modifications on NODE structure as
described at (1).
(3) Rewriting MT::Builder and MT::Template methods so as to use newly
added interface.
Yes, it's very straightforward.
----
How do you think about these changes? Meaningful?
--
Hirotaka Ogawa makes no sense.
http://as-is.net/blog/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mtos-r1431-mt-template-node.patch
Type: text/x-patch
Size: 13098 bytes
Desc: not available
Url : http://www.sixapart.com/pipermail/mtos-dev/attachments/20080302/19bf3e22/attachment-0001.bin
More information about the MTOS-dev
mailing list