Slash Boxes
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)

  (email not shown publicly)

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

Journal of malte (1708)

Wednesday March 05, 2008
03:29 PM

Joose has Roles

[ #35843 ]

Joose the JavaScript implementation of Moose now has Roles.

A direct translation of the Synopsis from Moose::Role looks like this:

Class("Eq", {meta: Joose.Role});

    notEqual: function (para) {
        return !this.isEqual(para)

has("value", {is: rw})


    initialize: function (value) {

    isEqual: function (cur) {
        return this.getValue() == cur.getValue()


The check() makes a "compile time" check of the role requirements. This might later be implemented as an onload-event in browsers.

Joose.Roles are themselves implemented as Joose.Classes. The source looks like this:


    initialize: function () {                = "Joose.Role"
        this.requiresMethodNames = [];

    addRequirement: function (methodName) {

    exportTo: function (classObject) {

    hasRequiredMethods: function (classObject) {
        var complete = true
        this.requiresMethodNames.each(function (value) {
            var found = classObject.meta.can(value)
            if(!found) {
                complete = false
        return complete

    isImplementedBy: function (classObject) {

        var complete = this.hasRequiredMethods(classObject);

        if(complete) {
            complete = this.implementsMyMethods(classObject);
        return complete

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Careful, roles are not just glorified exporters, there is a lot more details that go into them. For instance, method conflict detection, which is different depending on if you are composing a role into a role or into a class. Otherwise, nice to see some more progress :)

    - Stevan

    • Hey, I need to take the same path as all the Perl Role/Trait modules :)
      • Yes, they all made the same mistakes cause they only attempted to replicate what was described in the basic overview paper on Traits. When I wrote Class::Trait, I read that paper as well as the "formal model" papers on the subject, and then re-read those same papers when writing Moose::Role.

        Having written several versions of a role system, it is tempting to try and keep it simple, but the reality is that it is not simple. I am only now happy with the current state of Moose roles, all other versions I h

    • I'll try to get Moose's roles test suite running eventually. I'm not really sure whether I'll do method wrappers, although the infrastructure is in place.

      I'd be interested if you feel that the overall design of Joose hits the spot or if it's doing something fundamentally wrong with respect to meta classes.

      • You seem to be on the right track, I will refrain from commenting on specifics since, as you said, its still very early in the life of the project. If you want to discuss specifics though, feel free to email me directly and we can talk.

        - Stevan