[Catalyst] Making a hash available across the application

Ram Dobson ram.dobson at nih.gov
Wed Mar 17 18:48:35 GMT 2010


I might do it a little different, but i like this Jshirley
On 3/17/2010 2:04 PM, J. Shirley wrote:
[snip]
>
-package MyApp::Schema;
+package MyApp;
>
> use Moose;
> extends 'DBIx::Class::Schema';
>

-has something =>  (

+has my_hash => (

>      is =>  ro,
>      lazy_build =>  1
> );
>
> sub _build_something {
>      my ( $self ) = @_;
-[ $self->resultset('Countries')->search({ foo =>  1 })->all ];
+[ $self->model('Countries')->search({ foo => 1 })->all;
+#TODO hashify that
> }
 > no Moose;

now getting your hash is as simple as $c->my_hash;
or if you're using TT [% c.myhash %]

I'm kinda new to Catalyst too, but i believe this is what one might call 
a "helper" function. Anybody who knows more have an opinion on the 
relative merit of my change?




>
> Then after that if you wish, you can do clear_something and it will be
> refetched.
>
> -J
>
> (Code untested, typed out quickly)
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list