// Copyright  2002 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.



#!/usr/bin/perl -w
use strict;
$|++;
	
use SOAP::Transport::HTTP;
	
my $daemon = SOAP::Transport::HTTP::Daemon
	  -> new (LocalAddr => 'localhost', LocalPort => 8001, Reuse => 1)
	  -> dispatch_to ('Server');
	
	print "Contact SOAP server at ", $daemon->url, "\n";
	$daemon->handle;
	
	BEGIN {
	  package Server;
	  use base qw(SOAP::Server::Parameters);
	
	  use XML::RSS;
	  use LWP::Simple;
	
	  sub fetch_headlines {
	    my $p = pop->method;
	    my $uri = $p->{uri} or die "missing uri parameter";
	    my $rdf = get $uri or die "Can't fetch rdf";
	    (my $rss = XML::RSS->new)->parse($rdf); # might die, we don't care
	
	    return [map {
	      my $item = $_;
	      +{ title => $item->{title}, link => $item->{link} };
	    } @{$rss->{items}}];
	  }
	}