Skip to content

Commit

Permalink
Merge cace0e5 into 141117f
Browse files Browse the repository at this point in the history
  • Loading branch information
andreeap committed Feb 19, 2015
2 parents 141117f + cace0e5 commit b9c41dc
Show file tree
Hide file tree
Showing 36 changed files with 1,132 additions and 455 deletions.
2 changes: 2 additions & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ equivalent_modules = Test::Routine
severity = 5

[ValuesAndExpressions::ProhibitInterpolationOfLiterals]
allow_if_string_contains_single_quote = 1
allow = qq{} qq[]
severity = 5

[ValuesAndExpressions::ProhibitNoisyQuotes]
Expand Down
4 changes: 3 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ requires 'MooseX::ClassAttribute';
requires 'MooseX::Getopt';
requires 'MooseX::Getopt::Dashes';
requires 'MooseX::Getopt::OptionTypeMap';
requires 'MooseX::StrictConstructor';
requires 'MooseX::Types';
requires 'MooseX::Types::Common::String';
requires 'MooseX::Types::ElasticSearch', ' == 0.0.2'; # Newer versions use the other ES module which we can't upgrade to yet b/c of ESX-Model.
requires 'MooseX::Types::Moose';
requires 'MooseX::Types::Path::Class';
requires 'MooseX::Types::Path::Class::MoreCoercions';
requires 'MooseX::Types::Structured';
requires 'MooseX::Types::URI';
requires 'Mozilla::CA';
Expand Down Expand Up @@ -167,6 +168,7 @@ test_requires 'Test::More', '0.99';
test_requires 'Test::Most';
test_requires 'Test::OpenID::Server';
test_requires 'Test::Perl::Critic';
test_requires 'Test::RequiresInternet';
test_requires 'Test::Routine', '0.012';
test_requires 'Test::Routine::Util', '0';

Expand Down
92 changes: 92 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,21 @@ DISTRIBUTIONS
ExtUtils::MakeMaker 6.59
Test::More 0.96
perl 5.008008
File-pushd-1.009
pathname: D/DA/DAGOLDEN/File-pushd-1.009.tar.gz
provides:
File::pushd 1.009
requirements:
Carp 0
Cwd 0
Exporter 0
ExtUtils::MakeMaker 6.17
File::Path 0
File::Spec 0
File::Temp 0
overload 0
strict 0
warnings 0
Filesys-Notify-Simple-0.12
pathname: M/MI/MIYAGAWA/Filesys-Notify-Simple-0.12.tar.gz
provides:
Expand Down Expand Up @@ -4884,6 +4899,25 @@ DISTRIBUTIONS
aliased 0
namespace::autoclean 0.12
namespace::clean 0
MooseX-StrictConstructor-0.19
pathname: D/DR/DROLSKY/MooseX-StrictConstructor-0.19.tar.gz
provides:
MooseX::StrictConstructor 0.19
MooseX::StrictConstructor::Trait::Class 0.19
MooseX::StrictConstructor::Trait::Method::Constructor 0.19
requirements:
B 0
ExtUtils::MakeMaker 6.30
Moose 0.94
Moose::Exporter 0
Moose::Role 0
Moose::Util::MetaRole 0
Test::Fatal 0
Test::Moose 0
Test::More 0.88
namespace::autoclean 0
strict 0
warnings 0
MooseX-Traits-Pluggable-0.12
pathname: R/RK/RKITOVER/MooseX-Traits-Pluggable-0.12.tar.gz
provides:
Expand Down Expand Up @@ -4966,6 +5000,34 @@ DISTRIBUTIONS
MooseX::Types 0.04
Path::Class 0.16
Test::More 0.88
MooseX-Types-Path-Class-MoreCoercions-0.003
pathname: D/DA/DAGOLDEN/MooseX-Types-Path-Class-MoreCoercions-0.003.tar.gz
provides:
MooseX::Types::Path::Class::MoreCoercions 0.003
requirements:
ExtUtils::MakeMaker 6.30
File::Find 0
File::Temp 0
File::pushd 0
Moose 0
MooseX::Types 0
MooseX::Types::Path::Class 0
MooseX::Types::Stringlike 0
Path::Class 0
Test::More 0.96
strict 0
warnings 0
MooseX-Types-Stringlike-0.003
pathname: D/DA/DAGOLDEN/MooseX-Types-Stringlike-0.003.tar.gz
provides:
MooseX::Types::Stringlike 0.003
requirements:
ExtUtils::MakeMaker 6.17
MooseX::Types 0
MooseX::Types::Moose 0
overload 0
strict 0
warnings 0
MooseX-Types-Structured-0.30
pathname: E/ET/ETHER/MooseX-Types-Structured-0.30.tar.gz
provides:
Expand Down Expand Up @@ -5397,6 +5459,27 @@ DISTRIBUTIONS
Test::Trap 0
overload 0
parent 0
PAUSE-Permissions-0.11
pathname: N/NE/NEILB/PAUSE-Permissions-0.11.tar.gz
provides:
PAUSE::Permissions 0.11
PAUSE::Permissions::Entry 0.11
PAUSE::Permissions::EntryIterator 0.11
PAUSE::Permissions::Module 0.11
PAUSE::Permissions::ModuleIterator 0.11
requirements:
Carp 0
ExtUtils::MakeMaker 0
File::HomeDir 0
File::Spec::Functions 0
HTTP::Date 0
HTTP::Tiny 0
Moo 0
autodie 0
feature 0
perl 5.010000
strict 0
warnings 0
POSIX-strftime-Compiler-0.31
pathname: K/KA/KAZEBURO/POSIX-strftime-Compiler-0.31.tar.gz
provides:
Expand Down Expand Up @@ -7174,6 +7257,15 @@ DISTRIBUTIONS
Test::Builder::Module 0
Test::More 0.61
perl 5.008_001
Test-RequiresInternet-0.04
pathname: M/MA/MALLEN/Test-RequiresInternet-0.04.tar.gz
provides:
Test::RequiresInternet 0.04
requirements:
ExtUtils::MakeMaker 0
Socket 0
strict 0
warnings 0
Test-Routine-0.018
pathname: R/RJ/RJBS/Test-Routine-0.018.tar.gz
provides:
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Document/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ has module => (
B<Required>
Release date (i.e. C<mtime> of the tarball).
Release date (i.e. C<mtime> of the archive file).
=cut

Expand Down Expand Up @@ -482,8 +482,8 @@ sub _build_slop {

=head2 stat
L<File::stat> info of the tarball. Contains C<mode>, C<uid>, C<gid>, C<size>
and C<mtime>.
L<File::stat> info of the archive file. Contains C<mode>, C<uid>,
C<gid>, C<size> and C<mtime>.
=cut

Expand Down
8 changes: 4 additions & 4 deletions lib/MetaCPAN/Document/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ PAUSE ID of the author.
=head2 archive
Name of the tarball (e.g. C<Some-Module-1.12.tar.gz>).
Name of the archive file (e.g. C<Some-Module-1.12.tar.gz>).
=head2 date
B<Required>
Release date (i.e. C<mtime> of the tarball).
Release date (i.e. C<mtime> of the archive file).
=head2 version
Expand Down Expand Up @@ -90,8 +90,8 @@ See L<CPAN::Meta::Spec/license>.
=head2 stat
L<File::stat> info of the tarball. Contains C<mode>, C<uid>, C<gid>, C<size>
and C<mtime>.
L<File::stat> info of the archive file. Contains C<mode>, C<uid>,
C<gid>, C<size> and C<mtime>.
=head2 first
Expand Down
150 changes: 150 additions & 0 deletions lib/MetaCPAN/Model/Archive.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package MetaCPAN::Model::Archive;

use v5.10;
use Moose;
use MooseX::StrictConstructor;
use MetaCPAN::Types qw(AbsFile AbsDir Bool);

use Archive::Any;
use Carp;
use File::Temp ();
use Path::Class ();

=head1 NAME
MetaCPAN::Model::Archive - Inspect and extract archive files
=head1 SYNOPSIS
use MetaCPAN::Model::Archive;
my $archive = MetaCPAN::Model::Archive->new( file => $some_file );
my $files = $archive->files;
my $extraction_dir = $archive->extract;
=head1 DESCRIPTION
This class manages getting information about and extraction of archive
files (tarballs, zipfiles, etc...) and their extraction directories.
The object is read-only and will only extract once. If you alter the
extraction directory and want a fresh one, make a new object.
The Archive will clean up its extraction directory upon destruction.
=head1 ATTRIBUTES
=head3 archive
I<Required>
The file to be extracted. It will be returned as a Path::Class
object.
=cut

has file => (
is => 'ro',
isa => AbsFile,
coerce => 1,
required => 1,
);

has _extractor => (
is => 'ro',
isa => 'Archive::Any',
handles => [
qw(
is_impolite
is_naughty
)
],
init_arg => undef,
lazy => 1,
default => sub {
my $self = shift;
croak $self->file . ' does not exist' unless -e $self->file;
return Archive::Any->new( $self->file );
},
);

# Holding the File::Temp::Dir object here is necessary to keep it
# alive until the object is destroyed. Path::Class::Dir will not hold
# onto the ojbect.
has _tempdir => (
is => 'ro',
isa => 'File::Temp::Dir',
init_arg => undef,
lazy => 1,
default => sub {
return File::Temp->newdir;
},
);

has extract_dir => (
is => 'ro',
isa => AbsDir,
lazy => 1,
coerce => 1,
default => sub {
my $self = shift;
return Path::Class::Dir->new( $self->_tempdir );
},
);

has _has_extracted => (
is => 'rw',
isa => Bool,
init_arg => undef,
default => 0,
);

=head1 METHODS
=head3 files
my $files = $archive->files;
A list of the files in the archive as an array ref.
=cut

# A cheap way to cache the result.
has files => (
is => 'ro',
isa => 'ArrayRef',
init_arg => undef,
lazy => 1,
default => sub {
my $self = shift;
return [ $self->_extractor->files ];
},
);

=head3 extract
my $extract_dir = $archive->extract;
Extract the archive into a temp directory. The directory will be a
L<Path::Class::Dir>.
Only the first call to extract will perform the extraction. After
that it will just return the extraction directory. If you want to
re-extract the archive, create a new object.
The extraction directory will be cleaned up when the object is destroyed.
=cut

sub extract {
my $self = shift;

return $self->extract_dir if $self->_has_extracted;

$self->_extractor->extract( $self->extract_dir );
$self->_has_extracted(1);

return $self->extract_dir;
}

1;
Loading

0 comments on commit b9c41dc

Please sign in to comment.