uG has asked for the wisdom of the Perl Monks concerning the following question:
The code above is meant to translate an rss feed.sub get_by_id { my ($self, $feed_id) = @_; my $feed = $self->single({id => $feed_id}); my $xml_feed = XML::Feed->parse(URI->new($feed->url)); $xml_feed->{'url'} = $feed->url; use WWW::Translate::Apertium; foreach ($xml_feed->entries) { my $engine = WWW::Translate::Apertium->new(lang_pair => 'en-ca'); my $translated_string = $engine->translate($_->content->body); #This change $_->content->body $_->content($translated_string); } return $xml_feed; }
The template above displays the translated content. However, if I would like to do[% FOREACH entry IN feed.entries %] TRANSLATED:[% entry.content.body %] [% END %]
It would seem I want to add an attribute (body_alt) to an XML::Feed::Content object. Am I on the right track? I want to believe $_->content->{body_alt} = $translated_string would do what I want, but i'm sure all you guys are about to point out why it doesn't do what I think it should (see second template).[% FOREACH entry IN feed.entries %] ORIGINAL:[% entry.content.body %] TRANSLATED:[% entry.content.body_alt %] [% END %]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Moose? Add a new attribute to a XML::Feed::Content object?
by Anonymous Monk on Mar 28, 2011 at 08:22 UTC | |
by uG (Scribe) on Mar 28, 2011 at 18:54 UTC | |
by Corion (Patriarch) on Mar 28, 2011 at 19:27 UTC | |
by uG (Scribe) on Mar 28, 2011 at 15:15 UTC | |
by Your Mother (Archbishop) on Mar 28, 2011 at 16:32 UTC |
Back to
Seekers of Perl Wisdom