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