Fix MANIFEST.SKIP (MYMETA fail)
[dbsrgits/SQL-Translator.git] / Makefile.PL
CommitLineData
bc38e1f5 1use inc::Module::Install 1.00;
6e64adbe 2use strict;
3use warnings;
4
475a7db7 5# to deal wuth x.y.z versions properly
6configure_requires 'ExtUtils::MakeMaker' => 6.54;
7
6e64adbe 8my $deps = {
9 requires => {
10 'Class::Base' => 0,
11 'Class::Data::Inheritable' => 0.02,
c092c5b3 12 'Digest::SHA' => 0,
467b7282 13 'Carp::Clan' => 0,
6e64adbe 14 'IO::Dir' => 0,
467b7282 15 'IO::Scalar' => 2.110,
bdf60588 16 'Parse::RecDescent' => 1.964001,
6e64adbe 17 'Pod::Usage' => 0,
6e64adbe 18 'DBI' => 0,
19 'File::ShareDir' => 1.0,
20 'File::Spec' => 0,
dd184b2c 21 'Scalar::Util' => 0,
dc34f950 22 'XML::Writer' => 0.500,
27ae9ae7 23 'Moo' => 0.009007,
6e64adbe 24 },
25 recommends => {
3e1ed76b 26 'Template' => 2.20,
02cc14bb 27 'GD' => 0,
28 'GraphViz' => 0,
29 'Graph::Directed' => 0,
30 'Spreadsheet::ParseExcel' => 0.41,
31 'Text::ParseWords' => 0,
32 'Text::RecordParser' => 0.02,
11ad2df9 33 'XML::LibXML' => 1.69,
6e64adbe 34 },
35 test_requires => {
dd299a76 36 'YAML' => 0.66,
02cc14bb 37 'File::Basename' => 0,
38 'Test::More' => 0.6,
39 'Test::Differences' => 0,
40 'Test::Exception' => 0,
6e64adbe 41 },
42};
43
44perl_version '5.005';
45
46name 'SQL-Translator';
47author 'Ken Youens-Clark <kclark@cpan.org>';
48abstract 'SQL DDL transformations and more';
44659089 49license 'gpl';
3f5ee660 50repository 'git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git';
6e64adbe 51bugtracker 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
52
53resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
54
55all_from 'lib/SQL/Translator.pm';
56
57for my $type (qw/requires recommends test_requires/) {
58 no strict qw/refs/;
59 my $f = \&$type;
60 for my $mod (keys %{$deps->{$type} || {} }) {
61 $f->($mod, $deps->{$type}{$mod});
62 }
63}
64
6e64adbe 65install_script (qw|
467b7282 66 script/sqlt-diagram
67 script/sqlt-diff
68 script/sqlt-diff-old
69 script/sqlt-dumper
70 script/sqlt-graph
71 script/sqlt
6e64adbe 72|);
73
74install_share();
75
aee4b66e 76tests_recursive ();
77
78
79# temporary(?) until I get around to fix M::I wrt xt/
80# needs Module::Install::AuthorTests
81eval {
82 # this should not be necessary since the autoloader is supposed
83 # to work, but there were reports of it failing
84 require Module::Install::AuthorTests;
85 recursive_author_tests (qw/xt/);
86 1;
87} || do {
88 if ($Module::Install::AUTHOR) {
89 my $err = $@;
90
91 # better error message in case of missing dep
92 eval { require Module::Install::AuthorTests }
93 || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";
94
95 die $err;
96 }
97};
6e64adbe 98
99auto_install();
100
dc34f950 101if ($Module::Install::AUTHOR) {
102 _recompile_grammars();
103 _recreate_rt_source();
104}
105
6e64adbe 106WriteAll();
dc34f950 107
dc34f950 108sub _recompile_grammars {
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}