Lose one more useless dependency
[dbsrgits/SQL-Translator.git] / Makefile.PL
CommitLineData
860d3652 1use inc::Module::Install 1.06;
6e64adbe 2use strict;
3use warnings;
4
475a7db7 5# to deal wuth x.y.z versions properly
cc553312 6configure_requires 'ExtUtils::MakeMaker' => '6.54';
475a7db7 7
860d3652 8perl_version '5.008001';
9
6e64adbe 10my $deps = {
11 requires => {
cc553312 12 'Digest::SHA' => '0',
13 'Carp::Clan' => '0',
7e666ece 14 'Parse::RecDescent' => '1.967009',
cc553312 15 'DBI' => '0',
16 'File::ShareDir' => '1.0',
cc553312 17 'XML::Writer' => '0.500',
a5bfeba8 18 'Moo' => '1.000003',
0fb58589 19 'Package::Variant' => '1.001001',
68d75205 20 'Sub::Quote' => '0',
45287c81 21 'Try::Tiny' => '0.04',
7c7966a1 22 'List::MoreUtils' => '0.09',
6e64adbe 23 },
24 recommends => {
cc553312 25 'Template' => '2.20',
26 'GD' => '0',
27 'GraphViz' => '0',
28 'Graph::Directed' => '0',
29 'Spreadsheet::ParseExcel' => '0.41',
cc553312 30 'Text::RecordParser' => '0.02',
31 'XML::LibXML' => '1.69',
6e64adbe 32 },
33 test_requires => {
cc553312 34 'YAML' => '0.66',
860d3652 35 'Test::More' => '0.88',
cc553312 36 'Test::Differences' => '0',
860d3652 37 'Test::Exception' => '0.31',
6e64adbe 38 },
39};
40
6e64adbe 41
42name 'SQL-Translator';
43author 'Ken Youens-Clark <kclark@cpan.org>';
44abstract 'SQL DDL transformations and more';
44659089 45license 'gpl';
3f5ee660 46repository 'git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git';
6e64adbe 47bugtracker 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
48
49resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
50
09d9cd5e 51Meta->{values}{x_authority} = 'cpan:JROBINSON';
52
6e64adbe 53all_from 'lib/SQL/Translator.pm';
54
55for my $type (qw/requires recommends test_requires/) {
56 no strict qw/refs/;
57 my $f = \&$type;
58 for my $mod (keys %{$deps->{$type} || {} }) {
59 $f->($mod, $deps->{$type}{$mod});
60 }
61}
62
6e64adbe 63install_script (qw|
467b7282 64 script/sqlt-diagram
65 script/sqlt-diff
66 script/sqlt-diff-old
67 script/sqlt-dumper
68 script/sqlt-graph
69 script/sqlt
6e64adbe 70|);
71
72install_share();
73
aee4b66e 74tests_recursive ();
75
76
77# temporary(?) until I get around to fix M::I wrt xt/
78# needs Module::Install::AuthorTests
79eval {
80 # this should not be necessary since the autoloader is supposed
81 # to work, but there were reports of it failing
82 require Module::Install::AuthorTests;
83 recursive_author_tests (qw/xt/);
84 1;
85} || do {
86 if ($Module::Install::AUTHOR) {
87 my $err = $@;
88
89 # better error message in case of missing dep
90 eval { require Module::Install::AuthorTests }
91 || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";
92
93 die $err;
94 }
95};
6e64adbe 96
97auto_install();
98
dc34f950 99if ($Module::Install::AUTHOR) {
100 _recompile_grammars();
101 _recreate_rt_source();
102}
103
6e64adbe 104WriteAll();
dc34f950 105
dc34f950 106sub _recompile_grammars {
0eb3b94a 107 return; # disabled until RT#74593 is resolved
108
bdf60588 109 require File::Spec;
110
111 my $compiled_parser_dir = File::Spec->catdir(qw/
112 share PrecompiledParsers Parse RecDescent DDL SQLT
113 /);
114
115 # Currently consider only single-name parsers containing a grammar marker
116 # This is somewhat fragile, but better than loading all kinds of parsers
117 # to some of which we may not even have the deps
118 my $parser_libdir = 'lib/SQL/Translator/Parser';
119 for my $parser_fn (glob "$parser_libdir/*.pm") {
120 die "$parser_fn does not look like a readable file\n"
121 unless ( -f $parser_fn and -r $parser_fn );
122
123 my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i
124 or die "$parser_fn not named in expected format\n";
125
126 my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> };
127 next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s;
128
129
130 my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm");
131
132 next if (
133 -f $precomp_parser_fn
134 and
135 (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9]
136 );
137
138
139 print "Precompiling parser for $type\n";
140
141 require $parser_fn;
142 require Parse::RecDescent;
143
144 Parse::RecDescent->Precompile(
145 do {
146 no strict 'refs';
147 ${"SQL::Translator::Parser::${type}::GRAMMAR"}
148 || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n"
149 },
150 "Parse::RecDescent::DDL::SQLT::$type"
151 );
152
153 rename( "$type.pm", $precomp_parser_fn )
154 or die "Unable to move $type.pm to $compiled_parser_dir: $!\n";
155 }
156
dc34f950 157}
158
159sub _recreate_rt_source {
160 my $base_xml = "t/data/roundtrip.xml";
161 my $autogen_yaml = "t/data/roundtrip_autogen.yaml";
162
163 print "Updating $autogen_yaml\n";
164
165 unlink $autogen_yaml;
166
167 eval {
168
169 use lib 'lib';
170
171 require SQL::Translator;
172 require SQL::Translator::Parser::XML;
173
174 open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n";
175
176 my $tr = SQL::Translator->new;
177 my $yaml = $tr->translate (
178 parser => 'XML',
179 file => $base_xml,
180 producer => 'YAML',
181 ) or die sprintf ("Unable to translate %s to YAML: %s\n",
182 $base_xml,
183 $tr->error || 'error unknown'
184 );
185
186 print $fh $yaml;
187 close $fh;
188 };
189
190 if ($@) {
d53db6a7 191 warn <<EOE;
dc34f950 192
193=========================================================================
d53db6a7 194=============== WARNING !!! =================
dc34f950 195=========================================================================
196
197Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
d53db6a7 198We will still generate a Makefile, but be aware that if you build a dist
199this way, it *WILL* be broken.
dc34f950 200
d53db6a7 201-------------------------------------------------------------------------
dc34f950 202$@
203
d53db6a7 204Press Enter to continue.
dc34f950 205EOE
d53db6a7 206 <>;
dc34f950 207 }
208}