<?xml version="1.0" encoding="windows-1252"?>
<node id="872182" title="How to organize Catalyst stash" created="2010-11-18 05:25:45" updated="2010-11-18 05:25:45">
<type id="115">
perlquestion</type>
<author id="575480">
roman</author>
<data>
<field name="doctext">
&lt;p&gt;I wonder how the fellowmonks pass their model objects into templates.
Do you pass directly the objects or do you expand them into individual properties (pass them as hashrefs)?&lt;/p&gt;

&lt;p&gt;If you use the first method (objects) how do you pass the additional information for the object?&lt;/p&gt;

&lt;p&gt;Let us say we need to display a list of some kind of payments (DBIx::Class objects).
It could be comfortable just:&lt;/p&gt;

&lt;code&gt;
$c-&gt;stash(payments =&gt; \@payments);
&lt;/code&gt;

&lt;p&gt;But there are other information we need to supply with each payment:
&lt;ul&gt;
&lt;li&gt;URLs (for payment detail, payment cancellation)&lt;/li&gt;
&lt;li&gt;textual descriptions for foreign keys values (
        payment state, payment method, ...)&lt;/li&gt;
&lt;li&gt;other payment properties not contained in the payment object. For example whether payment is due (would be displayed in red).&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;

&lt;p&gt;So would you pass the list like this:

&lt;code&gt;
$c-&gt;stash-&gt;{payments} = [
    map {
        {   is_due =&gt; $this-&gt;is_due( $c, $_ ),
            cancel_url =&gt; $c-&gt;uri_for_action( '/payment/cancel', [ $_-&gt;id ] ),
            detail_url =&gt; $c-&gt;uri_for_action( '/payment/view',   [ $_-&gt;id ] ),
            payment_method =&gt;
                $this-&gt;payment_method_descr_for( $c, $_-&gt;payment_method_id ),

            # how about the original object ?
            payment =&gt; $_,

            # or
            payment_id       =&gt; $_-&gt;id,
            payment_quantity =&gt; $_-&gt;quantity,

            # ....
        }
        } @payments
];
&lt;/code&gt;

or would you pass just the payments and compute the additional info (and URLs) in template
(It doesn't seem very MVCish to me)?&lt;/p&gt;

&lt;p&gt;Finally how do you pass dates? As objects or formatted already?&lt;/p&gt;

&lt;p&gt;Any comments are really appreciated.&lt;/p&gt;</field>
</data>
</node>
