Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

malte (1708)

malte
  (email not shown publicly)
http://joose-js.blogspot.com/

Working on Joose JavaScript meta system (Blog) [blogspot.com] and blok [appspot.com], a web based application for collaborative ui prototyping.

Journal of malte (1708)

Friday March 21, 2008
04:21 AM

Joose now has method modifiers

[ #35950 ]
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).

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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
    • 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.