in reply to Mouse as prelude to Moose?

hmm that's cute, you can mis-spell 'is' and the code still works:
package M1; use Mouse; has 'x' => (is => 'rw'); has 'y' => (ks => 'rw'); 1; use M1; my $m = M1->new(x => 55); warn $m->x; $m->x(888); warn $m->x;
UPDATE it's not that it works because the accessor is not actually formed. It's just no error is thrown. Just put a call to $m->y and you will see Can't locate object method "y" via package...

Replies are listed 'Best First'.
Re^2: Mouse as prelude to Moose?
by jasonk (Parson) on Feb 05, 2009 at 21:11 UTC

    By default Moose (and I'd assume also Mouse) will allow you to pass any keys you want to an object constructor. So what happens is just that the ks is being ignored. The reason it doesn't throw an error for an unknown key is so you can do something like this:

    package Foo; use Moose; has 'number' => ( is => 'rw', isa => 'Num', ); sub BUILD { my ( $self, $args ) = @_; $self->number( $args->{ 'foo' } * 42 ); }

    You can turn this behavior off for your own modules with MooseX::StrictConstructor.


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!