Sure, I was more commenting on the trade off as an aside and why it isn't in Moose core.
-Chris On Monday, May 20, 2013, Darren Duncan wrote: > If that was just done as part of a test suite though, and not in > production, the performance hit might be worth it. -- Darren Duncan > > On 2013.05.20 3:07 PM, Chris Prather wrote: > >> Using the hashref directly totally circumvents moose. You would need to >> write >> something like MooseX::Globref that replaces the instance type with a >> restricted >> hash. This would seriously impact performance. >> >> -Chris >> — >> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >> >> >> On Mon, May 20, 2013 at 5:55 PM, Sam Brain <s...@stanford.edu >> <mailto:s...@stanford.edu>> wrote: >> >> I have a simple application which uses Moose (example copied from >> Moose::Manual::MooseX pages) >> >> package User; >> >> use Moose; >> use MooseX::StrictConstructor; >> use namespace::autoclean; >> >> has 'name' => (is => 'rw', isa => 'Str'); >> has 'email' => (is => 'rw', isa => 'Str'); >> >> package main; >> >> my $bob = User->new( name => 'Bob', email => 'b...@example.com' ); >> >> say $bob->name; # prints 'Bob' >> say $bob->naem; # Exits with error: 'Can't locate object method >> "naem" .. >> >> All is good so far. >> Then, much later, in an Idiot Moment, I forgot my "objects" were Moose >> objects and not hashrefs, and wrote: >> >> say $bob->{name}; # prints 'Bob' (!) >> >> say "OK" unless($bob->{naem}); # prints "OK", gives no error! >> >> $bob->name = "Robert"; # dies with "Can't modify non-lvalue >> subroutine >> call..." - Good! >> $bob->{name} = "Robert"; # doesn't die! >> >> say $bob->name; # prints 'Robert' (!) >> >> $bob->{naem} = "Roberto"; >> >> say $bob->{naem}; # prints 'Roberto' (!) >> >> say $bob->naem; # Exits with error: 'Can't locate object method >> "naem" ' (Whew!) >> >> say Dumper($bob); # gives: >> # $VAR1 = bless( { >> # 'email' => 'b...@example.com', >> # 'naem' => 'Roberto', >> # 'name' => 'Robert' >> # }, 'User' ); >> >> Now I know any software cannot be totally immune from extreme idiocy >> like >> mine, but I was surprised how quickly I got myself in trouble. Is >> there a >> MooseX::StrictSomething which could have help me avoided this? (Yes I >> know: >> "more exercise of the Little Grey Cells" - apart from that?) >> >> Thanks >> >> Sam Brain >> >> -- >> Sam Brain >> Department of Radiation Oncology >> Stanford Cancer Center >> Phone: 650-723-6967 >> >> >> >