-# $Id: Build.PL,v 1.8 2005-06-28 21:43:49 duality72 Exp $
+# $Id: Build.PL,v 1.9 2006-01-20 15:04:55 grommit Exp $
use strict;
-use Module::Build;
+use lib './lib';
+use SQL::Translator::Module::Build;
-my $builder = Module::Build->new(
+my $builder = SQL::Translator::Module::Build->new(
create_readme => 0,
dist_abstract => 'SQL DDL transformations and more',
dist_author => 'Ken Y. Clark <kclark@cpan.org>',
'Test::More' => 0.6,
'Test::Exception' => 0,
'Test::Differences' => 0,
- }
+ },
+
+ get_options => {
+ # Where to store additional files such as templates.
+ # TODO: Should be OS dependant. See Module::Build::os_type()
+ install_dir => { type=>'=s', default=>'/usr/local/share/sqlfairy' },
+ },
);
+
+my $install_dir = $builder->args('install_dir');
+print "SqlFairy needs to install some additional files such as templates.\n";
+$install_dir = $builder->prompt( "Where should they go?", $install_dir );
+print "\n";
+
+# Add the install (and template) dir to the config data. They will then be
+# available via the (Module::Build) generated SQL::Translator::ConfigData.
+# During build time they are availiable from $builder->config_data( NAME )
+my $template_dir = "$install_dir/template";
+$builder->config_data( install_dir => $install_dir );
+$builder->config_data( template_dir => $template_dir );
+
+# Add build element for templates, these are processed by
+# SQL::Translator::Module::Build::process_template_files
+$builder->add_build_element('template');
+$builder->install_path->{template} = $template_dir;
+
+
$builder->create_build_script;
print "Now run './Build', './Build test', and './Build install'\n";
--- /dev/null
+package SQL::Translator::Module::Build;
+
+use strict;
+use warnings;
+use File::Find;
+
+use base qw/Module::Build/;
+
+# Copies contents of ./templates into blib/templates. These are then installed
+# based on the install_paths setting given to the constructor.
+# Called by Module::Build due to add_build_element call in Build.PL
+sub process_template_files {
+ my $build = shift;
+ find({
+ no_chdir => 1,
+ wanted => sub {
+ return unless -f $_;
+ $build->copy_if_modified( from => $_, to_dir => "blib", verbose => 1);
+ },
+ },'templates');
+}
+
+# Install the templates copied into blib above. Uses
+sub ACTION_install {
+ my $build = shift;
+ $build->SUPER::ACTION_install(@_);
+ require ExtUtils::Install;
+ my $install_to = $build->config_data( 'template_dir' );
+ ExtUtils::Install::install(
+ { 'templates' => $install_to }, 1, 0, $build->{args}{uninst} || 0 );
+}
+
+1;