All pastes #260140 Raw Edit

Unnamed

public text v1 · immutable
#260140 ·published 2006-11-28 01:35 UTC
rendered paste body
package Emureports::Controller::Aggregator;

use strict;
use warnings;
use base 'Catalyst::Controller';

=head1 NAME

Emureports::Controller::Aggregator - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index 

=cut
use LWP::UserAgent;
use XML::Feed;
use threads;

sub setup_request : Local {
	my ($self,$c,$url)=@_;

	my $ua = LWP::UserAgent->new();
	$ua->agent('EmuReports/0.1');
	my $req = HTTP::Request->new(GET => $url);
	my $res = $ua->request($req);
	my $feed = $res->{_content};
	$c->stash->{xml} = XML::Feed->parse(\$feed);
}

sub get_emuscene : Local {
	my ($self,$c)=@_;
	
	# my $thr=threads->create('emuscene_thread',$c);
	# $thr->detach();
	my $pid = fork();
	if($pid==0) {
		&emuscene_thread($c);
	}
	else {
		$c->res->body('Grabbing Emuscene Feeds');
	}
}

sub emuscene_thread {
	my $c = shift;
	
	$c->model('EmuReports::FeedUpdates')->delete();
	$c->forward('/aggregator/setup_request',['http://www.emuscene.com/rss.php']);
	
	foreach my $node ($c->stash->{xml}->entries()) {
		my $f = $c->model('EmuReports::FeedUpdates')->new({});
		my ($name,$title) = $node->title() =~ /(.*?) Updated to (.*?)$/i;
		$f->name($name);
		$f->title('Updated to ' . $title);
		$f->link($node->link());
		$f->insert();
	}
}


=head1 AUTHOR

Victor Igumnov

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;