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