Permalink
Browse files

- some progress

  • Loading branch information...
1 parent cc128a9 commit 5fb41afaa0855314825612262a7ca0939c14fc58 @SamuraiJack committed Apr 23, 2010
Showing with 96 additions and 79 deletions.
  1. +5 −8 MANIFEST
  2. +57 −0 MANIFEST.SKIP
  3. +32 −46 lib/Data/Visitor.js
  4. +2 −25 t/010_basics.t.js
View
@@ -1,19 +1,16 @@
-Build.PL
Changes
-doc/html/Data/Visitor.html
-doc/html/Data/Visitor/Class.html
-doc/mmd/Data/Visitor.txt
-doc/mmd/Data/Visitor/Class.txt
inc/Module/Build/Functions.pm
inc/Module/Build/Functions/DSL.pm
+inc/Module/Build/JSAN.pm
inc/Module/Build/JSAN/Installable.pm
inc/Module/JSAN.pm
inc/Module/JSAN/DSL.pm
INSTALL
lib/Data/Visitor.js
-lib/Data/Visitor/Class.js
-MANIFEST This list of files
+lib/Data/Visitor.mmd
+MANIFEST
META.json
README.md
-t/010_sanity.t.js
+t/010_basics.t.js
t/index.html
+TODO
View
@@ -0,0 +1,57 @@
+
+#!start included /usr/local/share/perl/5.10.0/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$ # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# Avoid Devel::Cover files.
+\bcover_db\b
+#!end included /usr/local/share/perl/5.10.0/ExtUtils/MANIFEST.SKIP
+
+# Avoid configuration metadata file
+^MYMETA\.
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\bBuild.bat$
+\b_build
+\bBuild.COM$
+\bBUILD.COM$
+\bbuild.com$
+^MANIFEST\.SKIP
+
+# Avoid archives of this distribution
+\bData.Visitor-[\d\.\_]+
+^Build.PL$
+.tar.gz$
+^tests/lib/
+Data.Visitor-0.01
+^\.project$
+^\.git\b
+^\.externalToolBuilders\b
View
@@ -9,41 +9,50 @@ Class('Data.Visitor', {
methods : {
visit : function () {
- var res = []
var seen = this.seen
Joose.A.each(arguments, function (value) {
if (value && typeof value == 'object' || typeof value == 'function') {
- var ref = value.__REF__
+ var ref = value.__ID__
- if (!ref) ref = value.__REF__ = this.my.getID()
+ if (!ref) ref = value.__ID__ = this.my.getRefAddr()
if (seen[ref])
- res.push(this.visitSeen(value))
+ this.visitSeen(value)
else
- res.push(this.visitNotSeen(value))
+ this.visitNotSeenObject(value)
} else
- res.push(this.visitValue(value))
+ this.visitValue(value)
}, this)
-
- if (res.length > 1) return res
- if (res.length == 1) return res[0]
-
- return undefined
},
- visitSeen : function (value) {
- return this.seen[ value.__REF__ ]
+ visitValue : function (value) {
},
- visitNotSeen : function (value) {
- return this.seen[ value.__REF__ ] = this.visitObject(value)
+ visitSeen : function (value, result) {
+ },
+
+
+ // XXX also handle RegExp, Date
+ visitNotSeenObject : function (value) {
+ this.seen[ value.__ID__ ] = value
+
+ if (Joose.O.isInstance(value))
+ this.visitInstance(value)
+ else
+ if (value instanceof Array)
+ this.visitArray(value)
+ else
+ if (typeof value == 'function')
+ this.visitFunction(value)
+ else
+ this.visitGenericObject(value)
},
@@ -53,64 +62,43 @@ Class('Data.Visitor', {
this.visitArrayEntry(value, index, array)
}, this)
-
- return array
},
visitArrayEntry : function (value, index, array) {
- return this.visit(value)
- },
-
-
- visitObject : function (value) {
- if (Joose.O.isInstance(value)) return this.visitInstance(value)
-
- if (value instanceof Array) return this.visitArray(value)
-
- if (typeof value == 'function') return this.visitFunction(value)
-
-
- return this.visitGenericObject(value)
- },
-
-
- visitValue : function (value) {
- return value
+ this.visit(value)
},
visitGenericObject : function (object) {
Joose.O.eachOwn(object, function (value, key) {
- if (key != '__REF__') {
+ if (key != '__ID__') {
this.visitObjectKey(key, value, object)
this.visitObjectValue(value, key, object)
}
}, this)
-
- return object
},
visitInstance : function (value) {
- return this.visitGenericObject(value)
+ this.visitGenericObject(value)
},
visitObjectKey : function (key, value, object) {
- return this.visitValue(key)
+ this.visitValue(key)
},
visitObjectValue : function (value, key, object) {
- return this.visit(value)
+ this.visit(value)
},
visitFunction : function (value) {
- return this.visitValue(value)
+ this.visitGenericObject(value)
}
},
@@ -124,15 +112,13 @@ body : function () {
my : {
has : {
- HOST : null,
-
- tidy : true
+ HOST : null
},
methods : {
- getID : function () {
+ getRefAddr : function () {
return ID++
},
View
@@ -1,6 +1,6 @@
StartTest(function(t) {
- t.plan(15)
+ t.plan(1)
var async0 = t.beginAsync()
@@ -12,28 +12,6 @@ StartTest(function(t) {
t.ok(Data.Visitor, "Data.Visitor is here")
- var data1 = {}
- var data2 = []
- var data3 = 10
- var data4 = true
-
- t.ok(data1 === Data.Visitor.my.visit(data1), "Visiting don't modify the data #1")
- t.ok(data2 === Data.Visitor.my.visit(data2), "Visiting don't modify the data #2")
- t.ok(data3 === Data.Visitor.my.visit(data3), "Visiting don't modify the data #3")
- t.ok(data4 === Data.Visitor.my.visit(data4), "Visiting don't modify the data #4")
-
-
- //======================================================================================================================================================================================================================================================
- t.diag('N-arity')
-
- var res = Data.Visitor.my.visit(data1, data2, data3, data4)
-
- t.ok(data1 === res[0], "Visiting don't modify the data #1")
- t.ok(data2 === res[1], "Visiting don't modify the data #2")
- t.ok(data3 === res[2], "Visiting don't modify the data #3")
- t.ok(data4 === res[3], "Visiting don't modify the data #4")
-
-
//======================================================================================================================================================================================================================================================
t.diag('Composite structures')
@@ -62,7 +40,7 @@ StartTest(function(t) {
visitInstance : function () { instanceCounter++ },
- visitObject : function () { objectCounter++ }
+ visitNotSeenObject : function () { objectCounter++ }
}
})
@@ -96,7 +74,6 @@ StartTest(function(t) {
t.ok(valuesCounter == 9, "Correct number of values visited")
-
t.endAsync(async0)
})
})

0 comments on commit 5fb41af

Please sign in to comment.