Perl-Dist

 view release on metacpan or  search on metacpan

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

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

=head1 DESCRIPTION

Perl::Dist::Machine is a Perl::Dist multiplexor.

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

Please note the API is still evolving, and as such will remain
undocumented for now.

However, if you are adventurous and happy to read the source code,
it should be pretty clear.

=cut

use 5.005;
use strict;
use Carp          'croak';
use File::Copy    ();
use Params::Util  qw{ _STRING _IDENTIFIER _ARRAY0 _HASH0 _DRIVER };
use File::HomeDir ();

use vars qw{$VERSION};
BEGIN {
	$VERSION = '1.16';
}

use Object::Tiny qw{
	class
	output
	state
};





#####################################################################
# Constructor

sub new {
	my $class = shift;

	# All passed arguments go into the common param pool by default
	my $self = bless { @_,
		dimensions => [ ],
		options    => { },
		state      => undef,
		eos        => 0, # End of State
	}, $class;

	# Check params
	unless ( 
		_DRIVER($self->class, 'Perl::Dist::Inno') or
		_DRIVER($self->class, 'Perl::Dist::WiX') ) {
		croak("Missing or invalid class param");
	}
	unless ( defined $self->output ) {
		$self->{output} = File::HomeDir->my_desktop;
	}
	unless ( _STRING($self->output) ) {
		croak("Missing or invalid output param");
	}
	unless ( -d $self->output and -w $self->output ) {
		my $output = $self->output;
		croak("The output directory '$output' does not exist, or is not writable");
	}
	if ( _HASH0($self->{common}) ) {
		$self->{common} = [ %{ $self->{common} } ];
	}
	unless ( _ARRAY0($self->{common}) ) {
		croak("Did not provide a common param");
	}

	return $self;
}

sub common {
	return @{$_[0]->{common}};
}

sub dimensions {
	return @{$_[0]->{dimensions}};
}





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

sub add_dimension {
	my $self = shift;
	my $name = _IDENTIFIER(shift) or croak("Missing or invalid dimension name");
	if ( defined $self->state ) {
		croak("Cannot alter params once iterating");
	}
	if ( $self->{options}->{$name} ) {
		croak("The dimension '$name' already exists");
	}
	push @{ $self->{dimensions} }, $name;
	$self->{options}->{$name} = [ ];
	return 1;
}

sub add_option {
	my $self = shift;
	my $name = _IDENTIFIER(shift) or croak("Missing or invalid dimension name");
	if ( defined $self->state ) {
		croak("Cannot alter params once iterating");
	}
	unless ( $self->{options}->{$name} ) {
		croak("The dimension '$name' does not exist");
	}
	push @{ $self->{options}->{$name} }, [ @_ ];
	return 1;
}



( run in 1.386 second using v1.01-cache-2.11-cpan-df04353d9ac )