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