Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

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

I'm stuck with the following problem at the moment:
In a Catalyst Controller I get a result that is a Bio::Seq object, which is an object containing biological sequence data and additional information about the sequence but it could be any other object, really.
In my views, I can then show a textual representation of the object, for example a Bio::Seq object has a 'seq' method that returns the actual sequence string (AGCAACG...), so in my (TT) view, I can have:

The sequence is:[% bio_seq.seq %]
where $c->stash->{bio_seq} was populated with a Bio::Seq object in the controller. So far so good...

What I would now want to do is to use the information that comes with the Bio::Seq object to render a more informative version of it, which should use styles to highlight some sequence features. Basically, I would like a view helper method that takes the Bio::Seq object as an argument and returns a snippet of HTML with the sequence and style information to insert into the view. I know how to use TT FILTERs but they wouldn't work with the object, so I found the 'expose_methods' config option in Catalyst::View::TT, which sound like just the ticket but I'm not having any luck with it.

sub bioseq :Global { my ( $self, $c ) = @_; my $bio_seq_obj = Bio::Seq->new(); # ... a lot of stuff, finally this: $c->{stash}{bio_seq} = $bio_seq_obj; }
In MyApp::View::TT (just a silly example that would return a static text just to see if it works)
__PACKAGE__->config( # some config ... expose_methods => [qw/colorised_seq_features/], ); # for testing purposes sub colorised_seq_features { return 'testing, testing, 1,2'; }
And in the template file that is rendered in the end:
The sequence is: [% colorised_seq_features(bio_seq) %]
But colorised_seq_features simply renders nothing and there is no error message either (I did turn on DEBUG in the View::TT config).
I tried to use a method name that definitely doesn't exist and the view still doesn't complain, so I'm not sure where thie is going wrong.
Does anybody have any experience with expose_methods? The documentation is very short and I can't find much else about it. I have used similar techniques (view helpers) in Ruby on Rails and I was hoping to use the same technique in Catalyst. Am I completely on the wrong tracks (excuse the pun...)? I should also mention that I could of course do all of this in the controller and populate the stash with a HTML snippet but I would like to use the same technique in different views and I really think that the controller shouldn't provide HTML snippets and let the view sort that out.
Thanks for your help!

In reply to Catalyst::VIew::TT - format an object by tospo

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2018-10-19 02:08 GMT
    Find Nodes?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...

      Results (106 votes). Check out past polls.