Moosetified

wirebird on 2008-02-03T20:57:02

So I'm greatly delaying the next release of Wirebird.Gamehawk by making it all Mooseified. It's great fun, though it seems to be impacting performance. Might just be the configuration of the test database, though, so I'm not sweating it yet.



But one thing is puzzling me.



package Wirebird::RESTful;
use Moose;
has 'response' => {is => 'rw', isa => 'HashRef'};




And then:



package Wirebird::RESTful::Forum;
extends 'Wirebird::RESTful';




So far, so good... not much different from the BankAccount balance in the Moose Cookbook, right? Wirebird::RESTful::Forum can play with $self->response all happy and fine.



Except when a sub in the base class, Wirebird::RESTful, tries to mess with $self->response, I get:



Can't locate object method "response" via package "Wirebird::RESTful::Forum".



Mysterious. And probably just another senior moment, but this time I'm not taking any decongestants, so I'll have to find another excuse: my moose is clearly Satan.


Very Odd

Stevan on 2008-02-04T15:18:59

Regarding performance, you should try making the classes immutable, it gives a serious performance boost at runtime for only slightly more of a compile time cost.

Your example has some syntax issues. To start with, "has" doesn't take a HASH-ref of options. Also, you are missing the "use Moose" line in ::Forum, so that ...

package Wirebird::RESTful::Forum;
extends 'Wirebird::RESTful';
Should be ...

package Wirebird::RESTful::Forum;
use Moose;
extends 'Wirebird::RESTful';

As for what else is going on with the error, I am at a loss. I have done this same thing 1000 times and I *know* we are testing this functionality. Perhaps if you can provide a small test case that illustrates the issue, that would be helpful.

- Stevan

Re:Very Odd

wirebird on 2008-02-04T16:54:03

The "use Moose" line is in ::Forum, actually. I elided a ton of stuff, and apparently got carried away there.

And... oh, hey, you're right. Curly braces *again.* That's it, I'm switching my tty font from Courier New to... um... let's try Lucida Console.

Interesting, though. W::R::Forum can play with the 'has' stuff just fine, curly braces and all. That was what threw me. And I just checked (with Lucida!) and all my other has's use parens just fine. And none of them use 'extends', which was why I figured that was the culprit.

Thanks muchly. And I'll look at the immutable thing, too.