[Dbix-class] Using DBIx::Class with HTML::Template - anyone doing it?

Kevin Old kevinold at gmail.com
Tue Oct 31 19:05:52 GMT 2006


On 10/31/06, Ash Berlin <ash at cpan.org> wrote:
> Kevin Old wrote:
> > Hello everyone,
> >
> > I'm trying to use DBIx::Class with HTML::Template and I can't seem to
> > get it to work.
> >
> > Here's how I'm calling DBIC and HTML::Template in my script:
> >
> > my $tmpl = HTML::Template->new( filename => "single_stories.tmpl",
> > die_on_bad_params => 1);
> > my @stories = $schema->resultset('Stories')->search( { user_id => 1234 }
> > )->all;
> >
> > if ( $stories ) {
> >    $tmpl->param( stories => $stories );
> >    print $tmpl->output;
> > }
> >
>
> Not sure if thats a transposition error,
>
> but dont you want:
>
> if ( \@stories ) {
>     $tmpl->param( stories => \@stories );
>     print $tmpl->output;
> }
>
> Anyway, take a look at the Cookbook, near the end there is a way to
> inflate to a hashref, which would do what you want in this case I
> suspect. Currently you'll have to write it yourself like in the
> cookbook, but by next release it will be part of the dist.

Sorry, that was a transposition error...should have been @stories in
the if statement.

When you say "near the end" this is what I think you're referring too, correct?
http://search.cpan.org/~danieltwc/DBIx-Class-0.07002/lib/DBIx/Class/Manual/Cookbook.pod#___top

So, basically you're telling me to override the inflate_result
subroutine to return what I want?  I don't want that data structure
returned every time I call that result set, just on certain occasions?

Was thinking I might be able to write a Component I could use and
"drop in" when I needed it that would maybe add another function so
that I could return this AoH of results.

Thanks,
Kevin
-- 
Kevin Old
kevinold at gmail.com



More information about the DBIx-Class mailing list