Joose now has method modifiers

malte on 2008-03-21T09:21:19

You can now use the following method modifiers in Joose:

Class("S3", {
	isa: S2,
	override: {
		two: function () { 
			this.result2 += "3"
			this.SUPER();
		}
	},
	before: {
		add: function () { this.result += "5" }
	}
	after: {
		add: function () { this.result += "7" }
	},
	wrap: {
		add: function (original) { this.result += "8"; original(); this.result += "9" }
	}
})

By using the excplicit override modifier you get access to the overridden method using this.SUPER(). This is basically the same as the wrap modifier, but it keeps the methods signature intact (wrap passes the wrapped function as the first parameter).


You++

Stevan on 2008-03-21T15:34:44

Wow, very cool to see so much progress. I like very much where this is going. Couple of questions for you:

  • Why "wrap" and not "around"?
  • Can the before/after/wrap methods be stacked? Can you add more than one of them basically.
  • Would you consider moving Joose to the Moose code repository? I am sure we could get several of the #moose people to help write more tests and such.
  • And lastly,.. have you given any thought to how this could be intergrated with MooseX::Storage's JSON dumping? Like a JooseX::Storage JSON component of some kind?

- Stevan

Re:You++

malte on 2008-03-21T15:51:12

Thanks for the feedback :)

Why "wrap" and not "around"?
Probably, because I looked at the prototype.js code too much :)

Can the before/after/wrap methods be stacked? Can you add more than one of them basically.
Yeah, they get inherited and you can add multiple wrappers for the same method in the same class.

Would you consider moving Joose to the Moose code repository? I am sure we could get several of the #moose people to help write more tests and such.
Sure, no problem.

And lastly,.. have you given any thought to how this could be intergrated with MooseX::Storage's JSON dumping? Like a JooseX::Storage JSON component of some kind?
I'll take a look at it.

Re:You++

malte on 2008-03-21T18:59:03

I refactored the Joose test suite, so that it is much more accessible. You can see the method wrapper tests here.