Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

DateTime ->epoch not working in Catalyst controller but 'does' in template?

by uG (Scribe)
on Apr 07, 2011 at 05:11 UTC ( #897931=perlquestion: print w/replies, xml ) Need Help??
uG has asked for the wisdom of the Perl Monks concerning the following question:

sub end : Private { my ( $self, $c ) = @_; my @posts = $c->model('DBIC::Post')->get_recent_posts(20); my $feed = XML::Feed->new($c->stash->{type}); $feed->title("Emo Sluts Porn Feed"); $feed->link($c->uri_for('/')); $feed->self_link('/'); $feed->description("Watch the hottest emo whores and sluts in porn + at - New emo pussy and ass posted daily."); $feed->author("Keagan"); $feed->language('en-US'); foreach my $post (@posts) { my $entry = XML::Feed::Entry->new($c->stash->{type}); my $slug = $post->title; $slug =~ s/-/ /g; $entry->link($c->uri_for('/gallery/'.$slug)); $entry->title($post->title); $entry->content($post->body); $entry->issued($post->date->epoch); $entry->modified($post->date->epoch); my $url_part = $post->title; $url_part =~ s/ /-/g; $entry->link($c->req->base.'gallery/'.$url_part); $feed->add_entry($entry); } my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "a +pplication/rss+xml"; $c->res->content_type($mime); $c->res->body($feed->as_xml); }
Caught exception in MediaBlogger::Controller::Feeds->end "Can't call m +ethod "year" without a package or object reference at /usr/local/shar +e/perl/5.10.1/DateTime/Format/ line 79." Error occurs from this: $entry->issued($post->date->epoch); $entry->modified($post->date->epoch);
I'm pretty confused at why the above gives me the error it does. I can call fine from a TT Template:
[% %]
Any pointers?

Replies are listed 'Best First'.
Re: DateTime ->epoch not working in Catalyst controller but 'does' in template?
by ikegami (Pope) on Apr 07, 2011 at 05:29 UTC
    The error says one is calling ->year on something that isn't a DateTime object. You didn't show any code that includes a call to ->year. But if it relates to the code you do show, then issued and/or modified expect a DateTime object, but you pass a number of seconds. Perhaps the code should be
    $entry->issued($post->date); $entry->modified($post->date);

    You've provided very little useful data, so I'm quite lucky if I'm guessing right. If not, please show the code that gives the error, tells us what the functions expect for parameters, and show us what actually gets sent as parameters.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://897931]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-05-26 19:57 GMT
Find Nodes?
    Voting Booth?