Pinwheel
view release on metacpan or search on metacpan
lib/Module/Build/PinwheelApp.pm view on Meta::CPAN
use Pinwheel;
use Module::Build;
use File::Slurp;
use IO::File;
use strict;
use warnings;
use base 'Module::Build';
__PACKAGE__->add_property( 'database_schema' => 'db/schema.sql' );
__PACKAGE__->add_property( 'spec_file' );
__PACKAGE__->add_property( 'rpm_name' );
__PACKAGE__->add_property( 'rpm_description' => 'Web application built using the Pinwheel Framework.' );
__PACKAGE__->add_property( 'rpm_group' => 'Applications/Internet' );
__PACKAGE__->add_property( 'rpm_release' => 1 );
# Add to the defaults
sub _set_defaults {
my $self = shift;
$self->SUPER::_set_defaults();
$self->build_requires->{'Module::Build'} = '0.28';
$self->build_requires->{'Pinwheel'} = $Pinwheel::VERSION;
$self->requires->{'Pinwheel'} = $Pinwheel::VERSION;
$self->test_files("t/*/*.t");
}
# Overide the default install_map to just copy everything from blib
sub install_map {
my ($self) = @_;
die "Error: install_base is not set" unless $self->install_base;
# Install everything in blib straight to the install base
return {
'read' => '', # To keep ExtUtils::Install quiet
'write' => '',
'blib' => $self->install_base
};
}
sub find_pinwheel_files {
my ($self, $dir) = @_;
my @result;
local $_; # find() can overwrite $_, so protect ourselves
my $subr = sub {
if (-f $File::Find::name && $File::Find::name !~ /\/\./) {
push @result, $File::Find::name;
}
};
File::Find::find({wanted => $subr, no_chdir => 1}, $dir);
return \@result;
}
sub copy_all_by_type {
my ($self, $dir) = @_;
my $files = $self->find_pinwheel_files($dir);
foreach my $file (@$files) {
next if $file =~ /\/\./;
$self->copy_if_modified(from => $file, to => File::Spec->catfile($self->blib, $file) );
}
}
sub ACTION_setup_test_db {
my ($self) = @_;
$self->depends_on('build');
# Enable Pinwheel test mode
$ENV{'PINWHEEL_TEST'} = 1;
# Load the Pinwheel application configuration
require "./blib/lib/Config/Pinwheel.pm";
require Pinwheel::Database;
# Drop existing tables
foreach my $table (Pinwheel::Database::tables()) {
Pinwheel::Database::do("DROP TABLE \`$table\`;") or
die "Failed to drop table: $table\n";
}
# Open the database schema file
my $schema = new IO::File($self->database_schema) or
die "Failed to open database schema: $!";
# Go through the file line by line, executing full statements
my $statement = '';
while(my $line = <$schema>) {
next if $line =~ /^\s*--/; # Ignore comment lines
next if $line =~ /^\s*$/; # Ignore blank lines
$statement .= $line;
if ($line =~ /;\s*$/) {
Pinwheel::Database::do($statement) or
die "Failed to execute SQL: $statement\n";
$statement = '';
}
}
$schema->close();
}
sub test_dir {
my ($self, $dir) = @_;
my $p = $self->{properties};
# Enable Pinwheel test mode
$ENV{'PINWHEEL_TEST'} = 1;
# Temporary modification to list of test files
local $p->{test_files} = "t/$dir/*.t";
# Protect others against our @INC changes
local @INC = @INC;
# Make sure we test the module in blib/
unshift @INC, File::Spec->catdir($p->{base_dir}, $self->blib, 'lib');
$self->do_tests;
}
( run in 1.777 second using v1.01-cache-2.11-cpan-39bf76dae61 )