From: Mark Addison Date: Fri, 20 Jan 2006 15:04:55 +0000 (+0000) Subject: Build support for installing templates. X-Git-Tag: v0.11008~473 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=50f63fb11060a1f9f0a013bd79ec05d94e4ee151;p=dbsrgits%2FSQL-Translator.git Build support for installing templates. --- diff --git a/Build.PL b/Build.PL index 34fcfd3..27a9fee 100644 --- a/Build.PL +++ b/Build.PL @@ -1,9 +1,10 @@ -# $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 ', @@ -46,7 +47,32 @@ my $builder = Module::Build->new( '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"; diff --git a/Changes b/Changes index cbfdf1f..77e89f7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ * Added mysql_character_set for 4.1+ -mda * Two experimental filters. -mda +* Added build support for installing templates. -mda # ----------------------------------------------------------- # 0.7 2005-06-10 diff --git a/lib/SQL/Translator/Module/Build.pm b/lib/SQL/Translator/Module/Build.pm new file mode 100644 index 0000000..5d0a7de --- /dev/null +++ b/lib/SQL/Translator/Module/Build.pm @@ -0,0 +1,33 @@ +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;