Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: What Does CPAN Mirror "Freshness Date" Mean?

by Intrepid (Deacon)
on Sep 10, 2007 at 19:26 UTC ( #638157=note: print w/ replies, xml ) Need Help??


in reply to What Does CPAN Mirror "Freshness Date" Mean?

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.


Comment on Re: What Does CPAN Mirror "Freshness Date" Mean?
Select or Download Code
Re^2: What Does CPAN Mirror "Freshness Date" Mean?
by DrHyde (Prior) on Sep 11, 2007 at 09:53 UTC
    Have you suggested adding this feature to Andreas? He's pretty responsive to feedback from users.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://638157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2014-07-14 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (266 votes), past polls