[Catalyst] InstancePerContext doesn't work in schema

Steve Kleiman steve at prodhub.com
Thu Jan 14 17:45:00 GMT 2010


Hey Tomas. Thank you very much for responding.

The challenge I've got is that sometimes I want a schema object to act on a date or time. However to do that properly, it needs access to the current user's time zone and locale. I gather you're suggesting I just pass in the time zone and locale to the object every time. Cool. I can refactor that.

How about handling something as straightforward as getting debug text within a Schema to the console, e.g.,
$c->log->debug("hello")

What's the recommended procedure for debugging outside the Controller?

Thanks again.

-steve


On Jan 14, 2010, at 6:10 AM, Tomas Doran wrote:

> Steve Kleiman wrote:
>> Having trouble with InstancePerContext in a schema.
> 
> This won't work. Ever.
> 
> InstancePerContext only works on Catalyst components, the schema isn't a component, the MyApp::Model::DB class is the component..
> 
> You'll want to add InstancePerContext to the model class and get that to pass stuff down into the schema..
> 
>> I'd like to be able to get at $c from within a schema definition. The $callsheet->context call does not throw an error and returns an undef value. So in the case below, I would expect console output to be 'good test' but instead I get "Can't call method "log" on an undefined value".
> 
> This is a spectacularly bad idea. Why?
> 
> (It's a much better idea to build some closures around $c which you can call to do things for you, and those pass those into the schema - then the schema has a coderef it can call to 'generate me a URI', but it still has no knowledge of Catalyst or $c so seperation of concerns is maintained).
> 
> Cheers
> t0m




More information about the Catalyst mailing list