1#!/usr/local/bin/perl
2#############################################################################
3#
4# Get the most recent version of File::Scan module from CPAN
5# Last Change: Sat Jan  4 16:42:17 WET 2003
6# Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>
7#
8#############################################################################
9use strict;
10use LWP::UserAgent;
11use HTTP::Request;
12use HTTP::Response;
13
14my $VERSION = "0.01";
15
16my $module = "File::Scan";
17my $dir = "";
18my $cpan = "http://www.cpan.org/authors/id/H/HD/HDIAS";
19my $url = "http://search.cpan.org/search?mode=module&format=xml&query=$module";
20
21&main();
22
23sub main {
24	my $content = &get_content($url);
25	$content =~ /<VERSION>(\d+\.\d+)<\/VERSION>/i;
26	my $file = "File-Scan-$1.tar.gz";
27	&save($file, &get_content("$cpan/$file"));
28	exit(0);
29}
30
31sub save {
32	my $file = shift;
33	my $content = shift;
34
35	$file = "$dir/$file" if($dir);
36	open(FILE, ">$file") or die("$!");
37	binmode(FILE);
38	print FILE $content;
39	close(FILE);
40	return();
41}
42
43sub get_content {
44	my $url = shift;
45
46	my $req = HTTP::Request->new(GET => $url);
47	my $ua = LWP::UserAgent->new();
48	my $response = $ua->request($req);
49	if($response->is_error()) {
50		print $response->status_line . "\n";
51		exit(0);
52	}
53	my $content = $response->content();
54	return($content);
55}
56