Author Topic: Coming back to the well...this time for a Perl question!  (Read 347 times)

Offline filmnazi

  • Full Member
  • ***
  • Posts: 142
  • libertarian whipping boy
Coming back to the well...this time for a Perl question!
« on: September 15, 2009, 08:10:08 AM »
Ok, so i found the perl script below which sets up a SOAP server that applescript can pass data to and from.  It returns the titles and their respective URLs from a given rss link back to applescript in a list form that I can easily extract speakable text from.  

I have two questions about this process.  Currently the only way I've found to run the script is from the terminal: perl (path to file), is there a way to turn it into a shell script, or failing that is there a way to run it from a shell script? Applescript can call shell scripts, but I can't seem to make it call this perl script.

Second, I haven't been able to figure out which part of the perl script to alter if I want to add more than just the headlines (tagged as title, i believe) and the URLs, I'd like to be able to add the descriptions as well.

(apple sample script provided without restriction)

#!/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}}];
     }
   }