#!/proj/ads/soft/utils/bin/perl5.8.0
#
# Sample PERL SOAP script to format bibliographic metadata according
# to the ITWG draft of oct 2002:
#
#
#   bibcode   => Standard bibcode string
#   sdesc     => Short identifier as above
#   desc      => Longer identifier as above
#   url       => Link to data associated with bibcode.
#   type      => Type of link (e.g. 'data', 'pdf', 'simbad')
#

use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
    -> dispatch_to('BibLinks')
    -> handle;


package BibLinks;

# simply return all links in the bibtable file
sub harvest {
    my $self = shift;
    my @results = ();

    # bibtable_file is a tab-separated table containing:
    #    bibcode, URL, description
    my $bibtable = "biblinks.tab";
    # all links that we output are of type 'data'; 
    # for a full list of ADS link types, see:
    # http://adsdoc.harvard.edu/abs_doc/help_pages/results.html#available_items
    my $linktype = 'data';
    my $sdesc = '[ADS]';   # this is a short description for each link

    open(my $bf, $bibtable) or die "error opening file $bibtable: $!";

    while (my $r = <$bf>) {
	chop($r);
	my ($bibcode,$url,$desc) = split(/\t/,$r);

	push(@results,{ 
	    bibcode => $bibcode, 
	    url     => $url,
	    desc    => $desc,
	    sdesc   => $sdesc,
	    type    => $linktype,
	});
    }
    return [ @results ];
}
