tospo has asked for the wisdom of the Perl Monks concerning the following question:
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:
where $c->stash->{bio_seq} was populated with a Bio::Seq object in the controller. So far so good...The sequence is:[% bio_seq.seq %]
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.
In MyApp::Controller::BioSeq.pm
In MyApp::View::TT (just a silly example that would return a static text just to see if it works)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; }
And in the template file that is rendered in the end:__PACKAGE__->config( # some config ... expose_methods => [qw/colorised_seq_features/], ); # for testing purposes sub colorised_seq_features { return 'testing, testing, 1,2'; }
But colorised_seq_features simply renders nothing and there is no error message either (I did turn on DEBUG in the View::TT config).The sequence is: [% colorised_seq_features(bio_seq) %]
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Catalyst::VIew::TT - format an object
by chrestomanci (Priest) on Jun 27, 2011 at 21:08 UTC | |
by tospo (Hermit) on Jun 27, 2011 at 21:50 UTC | |
Re: Catalyst::VIew::TT - format an object
by tospo (Hermit) on Jun 28, 2011 at 13:18 UTC |