| 1 | package PITA::Scheme::Perl5::Make; | ||
| 2 | |||
| 3 | # Class for implementing the perl5-make testing scheme | ||
| 4 | |||
| 5 | use 5.005; | ||
| 6 | use strict; | ||
| 7 | use Carp (); | ||
| 8 | use Config (); | ||
| 9 | use File::Which (); | ||
| 10 | use PITA::Scheme::Perl (); | ||
| 11 | |||
| 12 | use vars qw{$VERSION @ISA}; | ||
| 13 | BEGIN { | ||
| 14 | $VERSION = '0.43'; | ||
| 15 | @ISA = 'PITA::Scheme::Perl'; | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | ##################################################################### | ||
| 23 | # Constructor | ||
| 24 | |||
| 25 | sub default_path { | ||
| 26 | File::Which::which('perl') || ''; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub new { | ||
| 30 | my $class = shift; | ||
| 31 | my $self = $class->SUPER::new(@_); | ||
| 32 | |||
| 33 | ### Additional checks | ||
| 34 | |||
| 35 | $self; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | ##################################################################### | ||
| 43 | # PITA::Scheme Methods | ||
| 44 | |||
| 45 | sub prepare_package { | ||
| 46 | my $self = shift; | ||
| 47 | |||
| 48 | # Do the generic unpacking | ||
| 49 | $self->SUPER::prepare_package(@_); | ||
| 50 | |||
| 51 | # Validate that the package has a Makefile.PL in the root | ||
| 52 | unless ( -f $self->workarea_file('Makefile.PL') ) { | ||
| 53 | Carp::croak("Package does not contain a Makefile.PL"); | ||
| 54 | } | ||
| 55 | |||
| 56 | $self; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub execute_all { | ||
| 60 | my $self = shift; | ||
| 61 | |||
| 62 | # Run the Makefile.PL | ||
| 63 | $self->execute_makefilepl or return ''; | ||
| 64 | |||
| 65 | # Run the make | ||
| 66 | $self->execute_make or return ''; | ||
| 67 | |||
| 68 | # Run the tests | ||
| 69 | $self->execute_maketest or return ''; | ||
| 70 | |||
| 71 | 1; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub execute_makefilepl { | ||
| 75 | my $self = shift; | ||
| 76 | unless ( -f $self->workarea_file('Makefile.PL') ) { | ||
| 77 | Carp::croak("Cannot execute_makefilepl without a Makefile.PL"); | ||
| 78 | } | ||
| 79 | |||
| 80 | # Run the Makefile.PL | ||
| 81 | my $command = $self->execute_command('perl', 'Makefile.PL'); | ||
| 82 | |||
| 83 | # Did it create a make file | ||
| 84 | if ( -f $self->workarea_file('Makefile') ) { | ||
| 85 | # Worked as expected | ||
| 86 | ### Do we need to add stuff here later? | ||
| 87 | return 1; | ||
| 88 | } | ||
| 89 | |||
| 90 | # Didn't work | ||
| 91 | ### Do we need to add stuff here later? | ||
| 92 | return ''; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub execute_make { | ||
| 96 | my $self = shift; | ||
| 97 | unless ( -f $self->workarea_file('Makefile') ) { | ||
| 98 | Carp::croak("Cannot execute_make without a Makefile"); | ||
| 99 | } | ||
| 100 | |||
| 101 | # Run make | ||
| 102 | my $make = $Config::Config{make} || 'make'; | ||
| 103 | my $command = $self->execute_command($make); | ||
| 104 | |||
| 105 | # Did it create a blib directory? | ||
| 106 | if ( -d $self->workarea_file('blib') ) { | ||
| 107 | # Worked as expected | ||
| 108 | ### Do we need to add stuff here later? | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | |||
| 112 | # Didn't work | ||
| 113 | ### Do we need to add stuff here later? | ||
| 114 | return ''; | ||
| 115 | } | ||
| 116 | |||
| 117 | sub execute_maketest { | ||
| 118 | my $self = shift; | ||
| 119 | unless ( -f $self->workarea_file('Makefile') ) { | ||
| 120 | Carp::croak("Cannot execute_maketest without a Makefile"); | ||
| 121 | } | ||
| 122 | unless ( -d $self->workarea_file('blib') ) { | ||
| 123 | Carp::croak("Cannot execute_maketest without a blib"); | ||
| 124 | } | ||
| 125 | |||
| 126 | # Run the make test | ||
| 127 | my $make = $Config::Config{make} || 'make'; | ||
| 128 | my $command = $self->execute_command($make, 'test'); | ||
| 129 | |||
| 130 | # Did it... erm... | ||
| 131 | if ( 1 ) { | ||
| 132 | # Worked as expected | ||
| 133 | ### Do we need to add stuff here later? | ||
| 134 | return 1; | ||
| 135 | } | ||
| 136 | |||
| 137 | # Didn't work | ||
| 138 | ### Do we need to add stuff here later? | ||
| 139 | return ''; | ||
| 140 | } | ||
| 141 | |||
| 142 | 1; |