| 1 | package Perl::Dist::Machine; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Perl::Dist::Machine - Generate an entire set of related distributions | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Perl::Dist::Machine is a Perl::Dist multiplexor. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | It provides the functionality required to generate several | ||||||||||||||||||||||||||||
| 14 | variations of a distribution at the same time. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Please note the API is still evolving, and as such will remain | ||||||||||||||||||||||||||||
| 17 | undocumented for now. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | However, if you are adventurous and happy to read the source code, | ||||||||||||||||||||||||||||
| 20 | it should be pretty clear. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use 5.005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use File::Copy (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Params::Util qw{ _STRING _IDENTIFIER _ARRAY0 _HASH0 _DRIVER }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use File::HomeDir (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 1 | $VERSION = '1.16'; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use Object::Tiny qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | class | ||||||||||||||||||||||||||||
| 38 | output | ||||||||||||||||||||||||||||
| 39 | state | ||||||||||||||||||||||||||||
| 40 | 1 | }; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ##################################################################### | ||||||||||||||||||||||||||||
| 47 | # Constructor | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # All passed arguments go into the common param pool by default | ||||||||||||||||||||||||||||
| 53 | 1 | my $self = bless { @_, | |||||||||||||||||||||||||||
| 54 | dimensions => [ ], | ||||||||||||||||||||||||||||
| 55 | options => { }, | ||||||||||||||||||||||||||||
| 56 | state => undef, | ||||||||||||||||||||||||||||
| 57 | eos => 0, # End of State | ||||||||||||||||||||||||||||
| 58 | }, $class; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Check params | ||||||||||||||||||||||||||||
| 61 | 1 | ▶ | unless ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&_DRIVER(scalar $self->class, "Perl::Dist::Inno") or &_DRIVER(scalar $self->class, "Perl::Dist::WiX")
MC/DC0%0/2
&_DRIVER(scalar $self->class, "Perl::Dist::Inno") or &_DRIVER(scalar $self->class, "Perl::Dist::WiX")
&_DRIVER(scalar $self->class, "Perl::Dist::Inno")
&_DRIVER(scalar $self->class, "Perl::Dist::WiX")
Truth table33%1/3
A or B
A= &_DRIVER(scalar $self->class, "Perl::Dist::Inno")B= &_DRIVER(scalar $self->class, "Perl::Dist::WiX")
| |||||||||||||||||||||||||||||
| 62 | _DRIVER($self->class, 'Perl::Dist::Inno') or | ||||||||||||||||||||||||||||
| 63 | _DRIVER($self->class, 'Perl::Dist::WiX') ) { | ||||||||||||||||||||||||||||
| 64 | 0 | croak("Missing or invalid class param"); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | unless ( defined $self->output ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->{output} = File::HomeDir->my_desktop; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 1 | ▶ | unless ( _STRING($self->output) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | croak("Missing or invalid output param"); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 1 | ▶ | unless ( -d $self->output and -w $self->output ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $self->output and -w $self->output
MC/DC0%0/2
-d $self->output and -w $self->output
-d $self->output
-w $self->output
Truth table33%1/3
A and B
A= -d $self->outputB= -w $self->output
| |||||||||||||||||||||||||||||
| 73 | 0 | my $output = $self->output; | |||||||||||||||||||||||||||
| 74 | 0 | croak("The output directory '$output' does not exist, or is not writable"); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | if ( _HASH0($self->{common}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 1 | $self->{common} = [ %{ $self->{common} } ]; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 1 | ▶ | unless ( _ARRAY0($self->{common}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | croak("Did not provide a common param"); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | return $self; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 6 | ▶ | sub common { | ||||||||||||||||||||||||||
|
Subroutine
common: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 6 | return @{$_[0]->{common}}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 15 | ▶ | sub dimensions { | ||||||||||||||||||||||||||
|
Subroutine
dimensions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 15 | return @{$_[0]->{dimensions}}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | ##################################################################### | ||||||||||||||||||||||||||||
| 99 | # Setup Methods | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub add_dimension { | ||||||||||||||||||||||||||
|
Subroutine
add_dimension: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 2 | ▶ | my $name = _IDENTIFIER(shift) or croak("Missing or invalid dimension name"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ( defined $self->state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | croak("Cannot alter params once iterating"); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 2 | ▶ | if ( $self->{options}->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | croak("The dimension '$name' already exists"); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 2 | push @{ $self->{dimensions} }, $name; | |||||||||||||||||||||||||||
| 111 | 2 | $self->{options}->{$name} = [ ]; | |||||||||||||||||||||||||||
| 112 | 2 | return 1; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | ▶ | sub add_option { | ||||||||||||||||||||||||||
|
Subroutine
add_option: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | 5 | ▶ | my $name = _IDENTIFIER(shift) or croak("Missing or invalid dimension name"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 5 | ▶ | if ( defined $self->state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | croak("Cannot alter params once iterating"); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 5 | ▶ | unless ( $self->{options}->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | croak("The dimension '$name' does not exist"); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 5 | push @{ $self->{options}->{$name} }, [ @_ ]; | |||||||||||||||||||||||||||
| 125 | 5 | return 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | ##################################################################### | ||||||||||||||||||||||||||||
| 133 | # Iterator Methods | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub all { | ||||||||||||||||||||||||||
|
Subroutine
all: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 137 | 1 | my @objects = (); | |||||||||||||||||||||||||||
| 138 | 1 | while ( 1 ) { | |||||||||||||||||||||||||||
| 139 | 7 | ▶ | my $object = $self->next or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 6 | push @objects, $object; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 1 | return @objects; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 7 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 146 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 147 | 7 | ▶ | if ( $self->{eos} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | # Already at last state | ||||||||||||||||||||||||||||
| 149 | 0 | return undef; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # Initialize the iterator if needed | ||||||||||||||||||||||||||||
| 153 | 7 | my $options = $self->{options}; | |||||||||||||||||||||||||||
| 154 | 7 | my $state = $self->state; | |||||||||||||||||||||||||||
| 155 | 7 | ▶ | if ( $state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | # Move to the next position | ||||||||||||||||||||||||||||
| 157 | 6 | my $found = 0; | |||||||||||||||||||||||||||
| 158 | 6 | foreach my $name ( $self->dimensions ) { | |||||||||||||||||||||||||||
| 159 | 9 | ▶ | unless ( $state->{$name} == $#{ $options->{$name} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | # Normal iteration | ||||||||||||||||||||||||||||
| 161 | 5 | $state->{$name}++; | |||||||||||||||||||||||||||
| 162 | 5 | $found = 1; | |||||||||||||||||||||||||||
| 163 | 5 | last; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # We've hit the end of a dimension. | ||||||||||||||||||||||||||||
| 167 | # Loop the state to the start, so the | ||||||||||||||||||||||||||||
| 168 | # next dimension will iterate to the | ||||||||||||||||||||||||||||
| 169 | # correct value. | ||||||||||||||||||||||||||||
| 170 | 4 | $state->{$name} = 0; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 6 | ▶ | unless ( $found ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 1 | $self->{eos} = 1; | |||||||||||||||||||||||||||
| 174 | 1 | return undef; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | # Initialize to the first position | ||||||||||||||||||||||||||||
| 178 | 1 | $state = $self->{state} = { }; | |||||||||||||||||||||||||||
| 179 | 1 | foreach my $name ( $self->dimensions ) { | |||||||||||||||||||||||||||
| 180 | 2 | ▶ | unless ( @{ $options->{$name} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | croak("No options for dimension '$name'"); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 2 | $state->{$name} = 0; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # Create the param-set | ||||||||||||||||||||||||||||
| 188 | 6 | my @params = $self->common; | |||||||||||||||||||||||||||
| 189 | 6 | foreach my $name ( $self->dimensions ) { | |||||||||||||||||||||||||||
| 190 | 12 | push @params, @{ $options->{$name}->[ $state->{$name} ] }; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # Create the object with those params | ||||||||||||||||||||||||||||
| 194 | 6 | return $self->class->new( @params ); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | ##################################################################### | ||||||||||||||||||||||||||||
| 202 | # Execution Methods | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | while ( my $dist = $self->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $dist->prepare; | |||||||||||||||||||||||||||
| 208 | 0 | $dist->run; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # Copy the output products for this run to the | ||||||||||||||||||||||||||||
| 211 | # main output area. | ||||||||||||||||||||||||||||
| 212 | 0 | foreach my $file ( @{$dist->output_file} ) { | |||||||||||||||||||||||||||
| 213 | 0 | File::Copy::move( $file, $self->output ); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # Flush out the image dir for the next run | ||||||||||||||||||||||||||||
| 217 | 0 | File::Remove::remove(\1, $dist->image_dir); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 0 | return 1; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 1 | 1; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =pod | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | Bugs should be reported via the CPAN bug tracker at | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Dist> | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | For other issues, contact the author. | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | Copyright 2007 - 2009 Adam Kennedy. | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 243 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 246 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||