Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perltidy

  • Loading branch information...
commit a6904c8b7edf74b7579944b670b2628c2ac75166 1 parent 00d562d
Léon Brocard authored
Showing with 106 additions and 96 deletions.
  1. +106 −96 lib/CPAN/Unpack.pm
202 lib/CPAN/Unpack.pm
View
@@ -15,116 +15,126 @@ $Archive::Extract::PREFER_BIN = 1;
our $VERSION = '0.30';
sub new {
- my $class = shift;
- my $self = {};
- bless $self, $class;
- return $self;
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ return $self;
}
sub unpack {
- my $self = shift;
- my $counter = 0;
+ my $self = shift;
+ my $counter = 0;
- my $cpan = $self->cpan;
- die "No $cpan" unless -d $cpan;
+ my $cpan = $self->cpan;
+ die "No $cpan" unless -d $cpan;
- my $destination = $self->destination;
- mkdir $destination;
- die "No $destination" unless -d $destination;
+ my $destination = $self->destination;
+ mkdir $destination;
+ die "No $destination" unless -d $destination;
- my $packages_filename = "$cpan/modules/02packages.details.txt.gz";
- die "No packages at $packages_filename" unless -f $packages_filename;
+ my $packages_filename = "$cpan/modules/02packages.details.txt.gz";
+ die "No packages at $packages_filename" unless -f $packages_filename;
- my %unpacked_versions;
- if (-e "$destination/unpacked_versions.yml") {
- local $/;
- open(my $fh, "<", "$destination/unpacked_versions.yml");
- %unpacked_versions = %{YAML::Any::Load(<$fh>)};
- close $fh;
- }
-
- sub fixme{
- my $path = $_;
- my $mode = (stat($path))[2];
- if(S_ISDIR($mode)) {
- chmod((S_IMODE($mode) | S_IRWXU), $path) unless (($mode & S_IRWXU) == S_IRWXU);
- }
- }
- my $p = Parse::CPAN::Packages::Fast->new($packages_filename);
- foreach my $distribution ($p->latest_distributions) {
- $counter++;
- my $want = "$destination/" . $distribution->dist;
- my $archive_filename = "$cpan/authors/id/" . $distribution->prefix;
-
- unless (-f $archive_filename) {
- warn "Archive $archive_filename not found";
- next;
- }
-
- my $unpacked = $unpacked_versions{$distribution->dist};
-
- if (!defined($distribution->version)) {
- # This is a bug in Parse::CPAN::Packages (and ::Fast). It affects a few
- # dozen packages, so use the mtime as version
- $unpacked_versions{$distribution->dist} = "x" . (stat $archive_filename)[9];
- }
- else {
- $unpacked_versions{$distribution->dist} = "x" . $distribution->version;
+ my %unpacked_versions;
+ if ( -e "$destination/unpacked_versions.yml" ) {
+ local $/;
+ open( my $fh, "<", "$destination/unpacked_versions.yml" );
+ %unpacked_versions = %{ YAML::Any::Load(<$fh>) };
+ close $fh;
}
- if (defined($unpacked) && $unpacked eq $unpacked_versions{$distribution->dist}) {
- print "Skipping " . $distribution->prefix . " ($counter)\n" unless $self->quiet;
- next;
+ sub fixme {
+ my $path = $_;
+ my $mode = ( stat($path) )[2];
+ if ( S_ISDIR($mode) ) {
+ chmod( ( S_IMODE($mode) | S_IRWXU ), $path )
+ unless ( ( $mode & S_IRWXU ) == S_IRWXU );
+ }
}
-
- if (-d $want) {
- print "Deleting old version of " . $distribution->dist . "\n" unless $self->quiet;
- rmtree "$destination/$want";
- }
-
- print "Unpacking " . $distribution->prefix . " ($counter)\n" unless $self->quiet;
-
- my $extract = Archive::Extract->new(archive => $archive_filename);
- my $to = "$destination/test";
- rmtree($to);
- mkdir($to);
- $extract->extract(to => $to);
-
- # Fix up broken permissions
- File::Find::find({ wanted => \&fixme, follow => 0, no_chdir => 1}, $to);
-
- my @files = <$to/*>;
- my $files = @files;
- if ($files == 1) {
- my $file = $files[0];
- if (S_ISDIR(stat($file))) {
- rename $file, $want;
- }
- else {
- mkdir $want;
- rename $file, "$want/" . basename($file);
- }
- rmdir $to;
- } else {
- rename $to, $want;
+ my $p = Parse::CPAN::Packages::Fast->new($packages_filename);
+ foreach my $distribution ( $p->latest_distributions ) {
+ $counter++;
+ my $want = "$destination/" . $distribution->dist;
+ my $archive_filename = "$cpan/authors/id/" . $distribution->prefix;
+
+ unless ( -f $archive_filename ) {
+ warn "Archive $archive_filename not found";
+ next;
+ }
+
+ my $unpacked = $unpacked_versions{ $distribution->dist };
+
+ if ( !defined( $distribution->version ) ) {
+
+ # This is a bug in Parse::CPAN::Packages (and ::Fast). It affects a few
+ # dozen packages, so use the mtime as version
+ $unpacked_versions{ $distribution->dist }
+ = "x" . ( stat $archive_filename )[9];
+ } else {
+ $unpacked_versions{ $distribution->dist }
+ = "x" . $distribution->version;
+ }
+
+ if ( defined($unpacked)
+ && $unpacked eq $unpacked_versions{ $distribution->dist } )
+ {
+ print "Skipping " . $distribution->prefix . " ($counter)\n"
+ unless $self->quiet;
+ next;
+ }
+
+ if ( -d $want ) {
+ print "Deleting old version of " . $distribution->dist . "\n"
+ unless $self->quiet;
+ rmtree "$destination/$want";
+ }
+
+ print "Unpacking " . $distribution->prefix . " ($counter)\n"
+ unless $self->quiet;
+
+ my $extract = Archive::Extract->new( archive => $archive_filename );
+ my $to = "$destination/test";
+ rmtree($to);
+ mkdir($to);
+ $extract->extract( to => $to );
+
+ # Fix up broken permissions
+ File::Find::find( { wanted => \&fixme, follow => 0, no_chdir => 1 },
+ $to );
+
+ my @files = <$to/*>;
+ my $files = @files;
+ if ( $files == 1 ) {
+ my $file = $files[0];
+ if ( S_ISDIR( stat($file) ) ) {
+ rename $file, $want;
+ } else {
+ mkdir $want;
+ rename $file, "$want/" . basename($file);
+ }
+ rmdir $to;
+ } else {
+ rename $to, $want;
+ }
+
+ unless ( $counter % 500 ) {
+
+ # Write this every now and then to prevent ^C from killing the list
+ open( my $fh, ">", "$destination/unpacked_versions.yml.tmp" );
+ print $fh YAML::Any::Dump( \%unpacked_versions );
+ close $fh;
+ rename "$destination/unpacked_versions.yml.tmp",
+ "$destination/unpacked_versions.yml";
+ }
}
- unless($counter % 500) {
- # Write this every now and then to prevent ^C from killing the list
- open(my $fh, ">", "$destination/unpacked_versions.yml.tmp");
- print $fh YAML::Any::Dump(\%unpacked_versions);
- close $fh;
- rename "$destination/unpacked_versions.yml.tmp", "$destination/unpacked_versions.yml";
- }
- }
-
- open(my $fh, ">", "$destination/unpacked_versions.yml.tmp");
- print $fh YAML::Any::Dump(\%unpacked_versions);
- close $fh;
- rename "$destination/unpacked_versions.yml.tmp", "$destination/unpacked_versions.yml";
+ open( my $fh, ">", "$destination/unpacked_versions.yml.tmp" );
+ print $fh YAML::Any::Dump( \%unpacked_versions );
+ close $fh;
+ rename "$destination/unpacked_versions.yml.tmp",
+ "$destination/unpacked_versions.yml";
}
-
__END__
=head1 NAME
Please sign in to comment.
Something went wrong with that request. Please try again.