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

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 EmoWomen.com - 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/W3CDTF.pm 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 post.date.epoch fine from a TT Template:
[% post.date.epoch %]
Any pointers?

Comment on DateTime ->epoch not working in Catalyst controller but 'does' in template?
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://897931]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-09-19 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls