| Perl-Dist-WiX documentation | Contained in the Perl-Dist-WiX distribution. |
Perl::Dist::WiX::Asset::Module - Module asset for a Win32 Perl
This document describes Perl::Dist::WiX::Asset::Module version 1.500.
my $distribution = Perl::Dist::WiX::Asset::Module->new(
parent => $dist,
name => 'DBI',
force => 0,
assume_installed => 0,
);
$distribution->install();
This asset installs a module from CPAN.
This class is a Perl::Dist::WiX::Role::Asset and shares its API.
The new constructor takes a series of parameters, validates then
and returns a new Perl::Dist::WiX::Asset::Module object, or throws
an exception on error.
It inherits all the parameters described in the Perl::Dist::WiX::Role::Asset->new() method documentation, and adds some additional parameters.
The required name param is the name of the module to be installed.
The optional boolean force param allows you to specify that the tests
should be skipped and the module installed without validating its
installation.
This can be set to true when there are test bugs that cause failing tests, or where true testing would be too difficult (for example, when a database connection is required.)
This defaults to the force() attribute of the Perl::Dist::WiX parent
object.
This tells the install() routine whether it has a packlist
that can be found once the module is installed or not.
This parameter defaults to true.
Some distributions (Bio::Perl, for example) do not include their version numbers in such a way that CPAN can tell whether they are up to date after installation via the CPAN::Module->uptodate() call.
This parameter, when set to 1, tells Perl::Dist::WiX to skip that verification step.
Specifies which feature the module is supposed to go in.
The install method installs the module described by the Perl::Dist::WiX::Asset::Module object and returns the files that were installed as a File::List::Object object.
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Dist-WiX
For other issues, contact the author.
Curtis Jewell <csjewell@cpan.org>
Adam Kennedy <adamk@cpan.org>
Copyright 2009 - 2011 Curtis Jewell.
Copyright 2007 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| Perl-Dist-WiX documentation | Contained in the Perl-Dist-WiX distribution. |
package Perl::Dist::WiX::Asset::Module;
use 5.010; use Moose; use MooseX::Types::Moose qw( Maybe Str Bool ); use English qw( -no_match_vars ); use File::Spec::Functions qw( catdir catfile ); require Perl::Dist::WiX::Exceptions; require File::List::Object; require IO::File; our $VERSION = '1.500001'; $VERSION =~ s/_//ms; with 'Perl::Dist::WiX::Role::NonURLAsset';
has name => ( is => 'ro', isa => Str, reader => 'get_name', required => 1, );
has force => ( is => 'bare', isa => Bool, reader => '_get_force', lazy => 1, default => sub { $_[0]->_get_parent()->force() ? 1 : 0 }, );
has packlist => ( is => 'bare', isa => Bool, reader => '_get_packlist', default => 1, );
has assume_installed => ( is => 'bare', isa => Bool, reader => '_get_assume', default => 0, );
has feature => ( is => 'bare', isa => Maybe [Str], reader => 'get_feature', default => undef, );
sub install { my $self = shift; # Set up variables needed. my $name = $self->get_name(); my $force = $self->_get_force(); my $assume = $self->_get_assume(); my $packlist_flag = $self->_get_packlist(); my $use_sqlite = $self->_use_sqlite(); my $vendor = !$self->_get_parent()->portable() ? 1 : ( $self->_get_parent()->perl_major_version() >= 12 ) ? 1 : 0; # Verify the existence of perl. if ( not $self->_get_bin_perl() ) { PDWiX->throw( 'Cannot install CPAN modules yet, perl is not installed'); } # Generate the CPAN installation script. my $dist_file = catfile( $self->_get_output_dir(), 'cpan_distro.txt' ); my $url = $self->_get_cpan()->as_string(); my $dp_dir = catdir( $self->_get_wix_dist_dir(), 'distroprefs' ); my $internet_available = ( $url =~ m{ \A file://}msx ) ? 1 : 0; my $cpan_string = <<"END_PERL"; print "Loading CPAN...\\n"; use CPAN 1.9600; CPAN::HandleConfig->load unless \$CPAN::Config_loaded++; \$CPAN::Config->{'urllist'} = [ '$url' ]; \$CPAN::Config->{'use_sqlite'} = q[$use_sqlite]; \$CPAN::Config->{'prefs_dir'} = q[$dp_dir]; \$CPAN::Config->{'patches_dir'} = q[$dp_dir]; \$CPAN::Config->{'prerequisites_policy'} = q[ignore]; \$CPAN::Config->{'connect_to_internet_ok'} = q[$internet_available]; \$CPAN::Config->{'ftp'} = q[]; if ($vendor) { \$CPAN::Config->{'makepl_arg'} = q[INSTALLDIRS=vendor]; \$CPAN::Config->{'make_install_arg'} = q[INSTALLDIRS=vendor]; \$CPAN::Config->{'mbuildpl_arg'} = q[--installdirs vendor]; \$CPAN::Config->{'mbuild_install_arg'} = q[--installdirs vendor]; } print "Installing $name from CPAN...\\n"; my \$module = CPAN::Shell->expandany( "$name" ) or die "CPAN.pm couldn't locate $name"; my \$dist_file = '$dist_file'; if ( \$module->uptodate ) { unlink \$dist_file; print "$name is up to date\\n"; exit(0); } SCOPE: { open( CPAN_FILE, '>', \$dist_file ) or die "open: \$!"; print CPAN_FILE \$module->distribution()->pretty_id() or die "print: \$!"; close( CPAN_FILE ) or die "close: \$!"; } print "\\\$ENV{PATH} = '\$ENV{PATH}'\\n"; if ( $force ) { CPAN::Shell->notest('install', '$name'); } else { CPAN::Shell->install('$name'); } print "Completed install of $name\\n"; unless ( $assume or \$module->uptodate() ) { die "Installation of $name appears to have failed"; } exit(0); END_PERL # Scan the perl directory if that's needed. my $filelist_sub; if ( not $self->_get_packlist() ) { $filelist_sub = File::List::Object->new()->readdir( $self->_dir('perl') ); $self->_trace_line( 5, "***** Module being installed $name" . " requires packlist => 0 *****\n" ); } # Dump the CPAN script to a temp file and execute $self->_trace_line( 1, "Running install of $name\n" ); $self->_trace_line( 2, ' at ' . localtime() . "\n" ); my $cpan_file = catfile( $self->_get_build_dir(), 'cpan_string.pl' ); SCOPE: { my $CPAN_FILE; open $CPAN_FILE, '>', $cpan_file or PDWiX->throw("CPAN script open failed: $OS_ERROR"); print {$CPAN_FILE} $cpan_string or PDWiX->throw("CPAN script print failed: $OS_ERROR"); close $CPAN_FILE or PDWiX->throw("CPAN script close failed: $OS_ERROR"); } local $ENV{PERL_MM_USE_DEFAULT} = 1; local $ENV{AUTOMATED_TESTING} = undef; local $ENV{RELEASE_TESTING} = undef; $self->_run3( $self->_get_bin_perl(), $cpan_file ) or PDWiX->throw('CPAN script execution failed'); if ($CHILD_ERROR) { PDWiX->throw( "Failure detected installing $name, stopping [$CHILD_ERROR]"); } # Read in the dist file and add it the the list of # distributions that were installed. if ( -r $dist_file ) { my $fh = IO::File->new( $dist_file, 'r' ); if ( not defined $fh ) { PDWiX->throw("CPAN modules file error: $OS_ERROR"); } my $dist_info = <$fh>; $fh->close; $self->_add_to_distributions_installed($dist_info); } else { $self->_trace_line( 0, "Distribution for module $name was up-to-date\n" ); } # Making final filelist. my $filelist; if ($packlist_flag) { $filelist = $self->_search_packlist($name); } else { $filelist = File::List::Object->new()->readdir( $self->_dir('perl') ); $filelist->subtract($filelist_sub)->filter( $self->_filters() ); } # Returns the filelist. return $filelist; } ## end sub install no Moose; __PACKAGE__->meta->make_immutable; 1; __END__