CPAN-Mini-Extract

 view release on metacpan or  search on metacpan

lib/CPAN/Mini/Extract.pm  view on Meta::CPAN

use Carp                         ();
use File::Basename               ();
use File::Path                   ();
use File::Spec              0.80 ();
use File::Remove            0.34 ();
use List::Util              1.15 ();
use File::HomeDir           0.88 ();
use File::Temp              0.21 ();
use URI                     1.37 ();
use URI::file                    ();
use IO::File                1.14 ();
use IO::Uncompress::Gunzip 2.017 ();
use Archive::Tar            1.22 ();
use Params::Util            1.00 ();
use LWP::Online             0.03 ();
use File::Find::Rule        0.30 ();
use CPAN::Mini          1.111004 ();

our $VERSION = '1.24';
our @ISA     = 'CPAN::Mini';



#####################################################################
# Constructor and Accessors

=pod

=head2 new

The C<new> constructor is used to create and configure a new CPAN
Processor. It takes a set of named params something like the following.

  # Create a CPAN processor
  my $Object = CPAN::Mini::Extract->new(
      # The normal CPAN::Mini params
      remote         => 'ftp://cpan.pair.com/pub/CPAN/',
      local          => '/home/adam/.minicpan',
      trace          => 1,
      
      # Additional params
      extract        => '/home/adam/explosion',
      extract_filter => sub { /\.pm$/ and ! /\b(inc|t)\b/ },
      extract_check  => 1,
      );

=over

=item minicpan args

C<CPAN::Mini::Extract> inherits from L<CPAN::Mini>, so all of the arguments
that can be used with L<CPAN::Mini> will also work with
C<CPAN::Mini::Extract>.

Please note that C<CPAN::Mini::Extract> applies some additional defaults
beyond the normal ones, like turning C<skip_perl> on.

=item offline

Although useless with L<CPAN::Mini> itself, the C<offline> flag will
cause the CPAN synchronisation step to be skipped, and only any
extraction tasks to be done. (False by default)

=item extract

Provides the directory (which must exist and be writable, or be creatable)
that the tarball dists should be extracted to.

=item extract_filter

C<CPAN::Mini::Extract> allows you to specify a filter controlling which
types of files are extracted from the Archive. Please note that ONLY
normal files are ever considered for extraction from an archive, with
any directories needed created automatically.

Although by default C<CPAN::Mini::Extract> only extract files of type .pm,
.t and .pl from the archives, you can add a list of additional things you
do not want to be extracted.

The filter should be provided as a subroutine reference. This sub will
be called with $_ set to the path of the file. The subroutine should
return true if the file is to be extracted, or false if not.

  # Extract all .pm files, except those in an include directory
  extract_filter => sub { /\.pm$/ and ! /\binc\b/ },

=item extract_check

The main extraction process is done as each new archive is downloaded,
but occasionally in a process this long-running something may go wrong
and you can end up with archives not extracted.

In addition, sometimes the processing of the extracted archives is
destructive and will result in them being deleted each run.

Once the mirror update has been completed, the C<extract_check> keyword
forces the processor to go back over every tarball in the mirror and
double check that it has a corrosponding extracted directory.

=item extract_force

For cases in which the filter has been changed, the C<extract_flush>
boolean flag can be used to forcefully delete and re-extract every
extracted directory.

=back

Returns a new C<CPAN::Mini::Extract> object, or dies on error.

=cut

sub new {
	my $class = shift;

	# Use the CPAN::Mini settings as defaults, and add any
	# additional explicit params.
	my %config = ( CPAN::Mini->read_config, @_ );

	# Unless provided auto-detect offline mode
	unless ( defined $config{offline} ) {
		$config{offline} = LWP::Online::offline();



( run in 0.440 second using v1.01-cache-2.11-cpan-2398b32b56e )