X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Makefile.PL;fp=Makefile.PL;h=a777e441d890c932091a82f95e0025426b394654;hb=bdf60588bb1e35e284bdc02c43d0ffe691994465;hp=2f90fe0eb71017b32c57e835fde41d61df838a4a;hpb=88ad825597d4eee0bf3c93aa81738f82cc583fae;p=dbsrgits%2FSQL-Translator.git diff --git a/Makefile.PL b/Makefile.PL index 2f90fe0..a777e44 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,7 +14,7 @@ my $deps = { 'Carp::Clan' => 0, 'IO::Dir' => 0, 'IO::Scalar' => 2.110, - 'Parse::RecDescent' => 1.962002, + 'Parse::RecDescent' => 1.964001, 'Pod::Usage' => 0, 'DBI' => 0, 'File::ShareDir' => 1.0, @@ -88,8 +88,54 @@ if ($Module::Install::AUTHOR) { WriteAll(); sub _recompile_grammars { - # placeholder, will be used to recompile P::RD parsers before shipping - # will also allow to lose dependency on P::RD + require File::Spec; + + my $compiled_parser_dir = File::Spec->catdir(qw/ + share PrecompiledParsers Parse RecDescent DDL SQLT + /); + + # Currently consider only single-name parsers containing a grammar marker + # This is somewhat fragile, but better than loading all kinds of parsers + # to some of which we may not even have the deps + my $parser_libdir = 'lib/SQL/Translator/Parser'; + for my $parser_fn (glob "$parser_libdir/*.pm") { + die "$parser_fn does not look like a readable file\n" + unless ( -f $parser_fn and -r $parser_fn ); + + my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i + or die "$parser_fn not named in expected format\n"; + + my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> }; + next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s; + + + my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm"); + + next if ( + -f $precomp_parser_fn + and + (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9] + ); + + + print "Precompiling parser for $type\n"; + + require $parser_fn; + require Parse::RecDescent; + + Parse::RecDescent->Precompile( + do { + no strict 'refs'; + ${"SQL::Translator::Parser::${type}::GRAMMAR"} + || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n" + }, + "Parse::RecDescent::DDL::SQLT::$type" + ); + + rename( "$type.pm", $precomp_parser_fn ) + or die "Unable to move $type.pm to $compiled_parser_dir: $!\n"; + } + } sub _recreate_rt_source {