Skip to content

Commit

Permalink
This, that and the other
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos committed Mar 12, 2010
1 parent dc11761 commit 3658111
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 9 deletions.
2 changes: 1 addition & 1 deletion check_installed.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
my $href = check_install( module => $module );
next unless $href;
if ( $mi ) {
print join(' ', 'requires', qq{'$module'}, '=>', (defined $href->{version} ? qq{'$href->{version}'} : q{'0'}) ), "\n";
print join(' ', 'requires', qq{'$module'}, '=>', (defined $href->{version} ? qq{'$href->{version}'} : q{'0'}) ), ";\n";
}
else {
print join(',',$module,(defined $href->{version} ? $href->{version} : '')), "\n";
Expand Down
10 changes: 2 additions & 8 deletions core.pl
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
use strict;

my $module = 'POE';
my $module = shift || die;

my $core = module_is_supplied_with_perl_core( $module );

print $core, "\n";

sub module_is_supplied_with_perl_core {
my $self = shift;
my $name = shift;
my $ver = shift || $];

### allow it to be called as a package function as well like:
### CPANPLUS::Module::module_is_supplied_with_perl_core('Config')
### so that we can check the status of modules that aren't released
### to CPAN, but are part of the core.
my $name = ref $self ? $self->module : $self;

### check Module::CoreList to see if it's a core package
require Module::CoreList;

Expand Down
89 changes: 89 additions & 0 deletions updater.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use strict;
use warnings;
use ExtUtils::Installed;
use File::Spec;
use File::Fetch;
use IO::Zlib;
use version;
use Module::Load::Conditional qw[check_install];
use CPANPLUS::Backend;

$ENV{PERL_MM_USE_DEFAULT} = 1; # despite verbose setting
$ENV{PERL_EXTUTILS_AUTOINSTALL} = '--defaultdeps';

my %installed;
my %cpan;

foreach my $module ( sort ExtUtils::Installed->new->modules() ) {
my $href = check_install( module => $module );
next unless $href;
$installed{ $module } = defined $href->{version} ? $href->{version} : 'undef';
}

my $loc = fetch_indexes('.','ftp://localhost/CPAN/') or die;
populate_cpan( $loc );
foreach my $module ( sort keys %installed ) {
# Eliminate core modules
if ( supplied_with_core( $module ) and !$cpan{ $module } ) {
delete $installed{ $module };
next;
}
if ( $installed{ $module } eq 'undef' and $cpan{ $module } eq 'undef' ) {
delete $installed{ $module };
next;
}
unless ( _vcmp( $cpan{ $module }, $installed{ $module} ) > 0 ) {
delete $installed{ $module };
next;
}
}

my $cb = CPANPLUS::Backend->new();
my $conf = $cb->configure_object;
$conf->set_conf( 'prereqs' => 1 );
foreach my $mod ( sort keys %installed ) {
my $module = $cb->module_tree($mod);
next unless $module;
$module->install();
}
exit 0;

sub supplied_with_core {
my $name = shift;
my $ver = shift || $];
require Module::CoreList;
return $Module::CoreList::version{ 0+$ver }->{ $name };
}

sub _vcmp {
my ($x, $y) = @_;
s/_//g foreach $x, $y;
return version->parse($x) <=> version->parse($y);
}

sub populate_cpan {
my $pfile = shift;
my $fh = IO::Zlib->new( $pfile, "rb" ) or die "$!\n";
my %dists;

while (<$fh>) {
last if /^\s*$/;
}
while (<$fh>) {
chomp;
my ($module,$version,$package_path) = split ' ', $_;
$cpan{ $module } = $version;
}
return 1;
}

sub fetch_indexes {
my ($location,$mirror) = @_;
my $packages = 'modules/02packages.details.txt.gz';
my $url = join '', $mirror, $packages;
my $ff = File::Fetch->new( uri => $url );
my $stat = $ff->fetch( to => $location );
return unless $stat;
print "Downloaded '$url' to '$stat'\n";
return $stat;
}

0 comments on commit 3658111

Please sign in to comment.