Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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)?

If you use the first method (objects) how do you pass the additional information for the object?

Let us say we need to display a list of some kind of payments (DBIx::Class objects). It could be comfortable just:

$c->stash(payments => \@payments);

But there are other information we need to supply with each payment:

  • URLs (for payment detail, payment cancellation)
  • textual descriptions for foreign keys values ( payment state, payment method, ...)
  • other payment properties not contained in the payment object. For example whether payment is due (would be displayed in red).

So would you pass the list like this:

$c->stash->{payments} = [ map { { is_due => $this->is_due( $c, $_ ), cancel_url => $c->uri_for_action( '/payment/cancel', [ $_- +>id ] ), detail_url => $c->uri_for_action( '/payment/view', [ $_- +>id ] ), payment_method => $this->payment_method_descr_for( $c, $_->payment_metho +d_id ), # how about the original object ? payment => $_, # or payment_id => $_->id, payment_quantity => $_->quantity, # .... } } @payments ];
or would you pass just the payments and compute the additional info (and URLs) in template (It doesn't seem very MVCish to me)?

Finally how do you pass dates? As objects or formatted already?

Any comments are really appreciated.

In reply to How to organize Catalyst stash by roman

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (8)
    As of 2017-11-22 22:03 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (327 votes). Check out past polls.