in reply to Moose or Mouse for production use

Here is some performance comparison between the two (among others), for a very narrow definition of "performance" (that doesn't seem to match what you're looking for but might be interesting to you nonetheless)

Replies are listed 'Best First'.
Re^2: Moose or Mouse for production use
by morgon (Priest) on Apr 01, 2009 at 15:42 UTC
    Thanks a lot for all replies - we'll probably go with Moose now.

    I have one more question:

    In a previous project I've used Class::Std and I quite like the strong encapsulation for object-attributes it provides.

    I just did some (very basic) playing around with Moose and wonder if there is any way to encapsulate object-attributes as well or if with Moose no access-control is possible.

    For example I was very surprised that you could do the following:

    <code>

    use strict;
    
    package Hubba;
    use Moose;
    
    has 'hubba' => ( is => "rw", isa => 'Int' );
    
    package main;
    no Moose;
    
    my $h = Hubba->new;
    
    $h->{hubba} = "Bubba";
    
    print $h->hubba
    
    </code>

    This actually prints "Bubba". In this example I declare a "hubba"-attribute of a "Hubba"-class to be of type Int, but still it is possible to subvert the type-system by accessing the attribute directly (or am I doing something wrong?)

    I don't think all of this will be a major concern for us, but still I would prefer stronger encapsulation - is that possible with Moose (or can you mix Moose and Class::Std)?

    Many thanks!

      Moose does not attempt to solve this, mostly because we see it as a social problem rather then a technical problem.

      If a co-worker writes code that accesses the underly HASH ref then they are breaking encapsulation (as well as general community coding standards). Once you discover this violation, you should talk to that person and explain why they shouldn't do it. If said co-worker continues to do this, then they should likely be fired or at least disciplined.

      Encapsulation is just a concept, something you can use to help write better code with. Encapsulation is not about completely preventing access to slots, but about providing clean and controlled ways to access slots. Moose accessors provide exactly that, a clean, consistent and controlled way to access your object's slots. What Class::Std (and all the other Inside-Out object systems) do is really just obsfucate slot access, an enterprising hacker can easily get past that encapsulation using modules like B and PadWalker.

      ... can you mix Moose and Class::Std?

      Not at all, they are two conflicting systems.

      -stvn
        Having to be constantly on the lookout for encapsulation breakage isn't fun nor practical. There is no need for anybody to get fired or even disciplined over this either. Much better have the code catastrophically fail and the co-worker given the opportunity to fix their mistake. Which is exactly what the various Inside-Out schemes out there provide (like my favorite Object::InsideOut).