I've got some code that is not a direct answer to your question but addresses a
related concern that CPAN users should have. It regards the freshness of the list
of mirrors which gets stored locally when the CPAN setup (init run) first takes
place. Due to what I consider a misdesign or missing feature of CPAN, that file is
never checked for staleness; thus if you do rerun a setup (cpan> o conf init)
some time, you will be presented with a list of mirrors to choose from that may
miss some good, recently-added ones that you'd want, or include some now bogus,
decommissioned ones that have had their virtual plugs pulled.
I use this as a shell (bash) function which I run when I feel like it. A more
automation-oriented person would likely want to make it into a cron job or
something similar.
#!/usr/bin/env perl
use File::stat;
use CPAN;
use LWP::Simple ("mirror");
use warnings;
use strict;
CPAN::Config->load;
my $fhost;
my $mbdata = $CPAN::Config->{keep_source_where}.q[/MIRRORED.BY];
if (-e $mbdata and -M _ < 14)
{
print qq[$mbdata: freshness is OK, it was last modified: ]
. gmtime stat($mbdata)->mtime()
} else {
($fhost)=grep(/^http/,@{$CPAN::Config->{urllist}});
die "No suitable cpan http mirror host, aborting. Sorry." unless $
+fhost;
printf qq[%s\n%s\n]
, qq[File $mbdata not found, or local file may be stale.]
, qq[will d/l fresh MIRRORED.BY file from $fhost, please wait
+...];
mirror($fhost .q[MIRRORED.BY] , $mbdata)
and print q[New MIRRORED.BY file timestamp in UTC: ]
. gmtime(stat($mbdata)->mtime) .qq[\n]
or die qq[Retrieval of MIRRORED.BY from $fhost FAILED. Sorry
+.]
}
Here's the bash-wrapped form of the same code:
function freshen_MIRROREDBY {
perl -MFile::stat -MCPAN -MLWP::Simple=mirror -le '
CPAN::Config->load;
my $fhost;
my $mbdata = $CPAN::Config->{keep_source_where}.q[/MIRRORED.BY
+];
if (-e $mbdata and -M _ < 14)
{
print qq[$mbdata: freshness is OK, last modified: ]
. gmtime stat($mbdata)->mtime()
} else {
($fhost)=grep(/^http/,@{$CPAN::Config->{urllist}});
die "No suitable cpan http mirror host, aborting. Sorry."
+unless $fhost;
printf qq[%s\n%s\n]
, qq[File $mbdata not found, or local file may be stale
+.]
, qq[will d/l fresh MIRRORED.BY file from $fhost, pleas
+e wait ...];
mirror($fhost .q[MIRRORED.BY] , $mbdata)
and print q[New MIRRORED.BY file timestamp in UTC: ]
. gmtime(stat($mbdata)->mtime) . qq[\n]
or die qq[Retrieval of MIRRORED.BY from $fhost FAIL
+ED. Sorry.]
}'
}
I hope this is useful to someone. I don't dare hope that the numerous anal among the
Perlmonks readership won't punish the posting of code as usual by finding some petty style
mistakes to justify a bitchy downvote orgy.
|