Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Mouse as prelude to Moose?

by metaperl (Curate)
on Feb 05, 2009 at 16:41 UTC ( [id://741598]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741598]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found