Perl-Dist-WiX

 view release on metacpan or  search on metacpan

lib/Perl/Dist/WiX/Util/Machine.pm  view on Meta::CPAN

package Perl::Dist::WiX::Util::Machine;

=pod

=head1 NAME

Perl::Dist::WiX::Util::Machine - Generate an entire set of related distributions

=head1 VERSION

This document describes Perl::Dist::WiX::Util::Machine version 1.500002.

=head1 SYNOPSIS

	# This is what Perl::Dist::Strawberry will do, as of version 2.03.

	# Create the machine
	my $machine = Perl::Dist::WiX::Util::Machine->new(
		class  => 'Perl::Dist::Strawberry',
		common => [ forceperl => 1 ],
		skip   => [4, 6],
	);

	# Set the different versions
	$machine->add_dimension('version');
	$machine->add_option('version',
		perl_version => '5101',
	);
	$machine->add_option('version',
		perl_version => '5101',
		portable     => 1,
	);
	$machine->add_option('version',
		perl_version => '5121',
		relocatable  => 1,
	);

	# Set the different paths
	$machine->add_dimension('drive');
	$machine->add_option('drive',
		image_dir => 'C:\strawberry',
	);
	$machine->add_option('drive',
		image_dir => 'D:\strawberry',
		msi       => 1,
		zip       => 0,
	);

	$machine->run();
	# Creates 8 distributions (really 6, because you can't have
	# portable => 1 and zip => 0 for the same distribution,
	# nor do we need to build a relocatable version twice.)	

=head1 DESCRIPTION

Perl::Dist::WiX::Util::Machine is a Perl::Dist::WiX multiplexer.

It provides the functionality required to generate several
variations of a distribution at the same time.

=cut

#<<<
use 5.010;
use Moose 0.90;
use Moose::Util::TypeConstraints;
use MooseX::Types::Moose         qw( Str ArrayRef HashRef Bool Int );
use Params::Util                 qw( _IDENTIFIER _HASH0 _DRIVER _CLASSISA );
use English                      qw( -no_match_vars );
use File::Copy                   qw();
use File::Copy::Recursive        qw();
use File::Path              2.08 qw( remove_tree );
use File::Spec::Functions        qw( catdir );
use File::Remove                 qw();
use File::HomeDir                qw();
use List::MoreUtils              qw( none );
use WiX3::Traceable              qw();
use Perl::Dist::WiX::Exceptions  qw();
#>>>

our $VERSION = '1.500002';

=head1 INTERFACE

=head2 new

	my $machine = Perl::Dist::WiX::Util::Machine->new(
		class => 'Perl::Dist::WiX',
		common => { forceperl => 1, },
		output => 'C:\',
		trace  => 2,
	);

This method creates a new object that generates multiple distributions,
using the parameters below.

=head3 class (required)

This required parameter specifies the class that this object uses to 
create distributions.

It must be a subclass of L<Perl::Dist::WiX|Perl::Dist::WiX>.

=cut



has class => (
	is  => 'ro',
	isa => subtype(
		'Str' => where {
			$_ ||= q{};

lib/Perl/Dist/WiX/Util/Machine.pm  view on Meta::CPAN

	# Check params
	if ( not _DRIVER( $self->_get_class(), 'Perl::Dist::WiX' ) ) {
		PDWiX->throw('Missing or invalid class param');
	}

	my $output = $self->_get_output();
	if ( not -d $output or not -w $output ) {
		PDWiX->throw( "The output directory '$output' does not "
			  . 'exist, or is not writable' );
	}

	return $self;
} ## end sub BUILD




#####################################################################
# Setup Methods

=head2 add_dimension

	$machine->add_dimension('perl_version');

Adds a 'dimension' (a set of options for different distributions) to the 
machine. 

The options are added by L<add_option|/add_option> calls using this 
dimension name.

Note that dimensions are multiplicative, so that if there are 3 dimensions 
defined in the machine, and they each have 3 options, 27 distributions will be 
generated.

=cut



sub add_dimension {
	my $self = shift;
	my $name = _IDENTIFIER(shift)
	  or PDWiX->throw('Missing or invalid dimension name');
	if ( $self->_has_state() ) {
		PDWiX->throw('Cannot alter params once iterating');
	}
	if ( $self->_option_exists($name) ) {
		PDWiX->throw("The dimension '$name' already exists");
	}

	$self->_add_dimension($name);
	$self->_set_options( $name => [] );
	return 1;
} ## end sub add_dimension



=head2 add_option

  $machine->add_option('perl_version',
    perl_version => '5120',
    relocatable => 1,
  );

Adds a 'option' (a set of parameters that can change) to a dimension. 

The first parameter is the dimension to add the option to, and the 
other parameters are stored in the dimension to be used when creating
objects.

The combination of the C<'common'> parameters and one option from each
dimension is used when creating or iterating through distribution objects.

=cut



sub add_option {
	my $self = shift;
	my $name = _IDENTIFIER(shift)
	  or PDWiX->throw('Missing or invalid dimension name');
	if ( $self->_has_state() ) {
		PDWiX->throw('Cannot alter params once iterating');
	}
	if ( not $self->_option_exists($name) ) {
		PDWiX->throw("The dimension '$name' does not exist");
	}
	my $option = $self->_get_options($name);
	push @{$option}, [@_];
	$self->_set_options( $name => $option );
	return 1;
} ## end sub add_option




#####################################################################
# Iterator Methods

sub _increment_state {
	my $self = shift;
	my $name = shift;

	my $number = $self->_get_state($name);
	$self->_set_state( $name, ++$number );

	return;
}



=head2 all

	my @dists = $machine->all();

Returns an array of objects that create all the possible 
distributions configured for this machine. 

=cut





( run in 0.521 second using v1.01-cache-2.11-cpan-71847e10f99 )