Add IRC metadata and update repository and bugtracker URLs
[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',
cf915bd8 15 'DBI' => '1.54',
cc553312 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',
3ab19c1b 22 'Scalar::Util' => '0',
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 => {
edc7ae17 34 'JSON' => '2.0',
cc553312 35 'YAML' => '0.66',
cb9a77e1 36 'XML::Writer' => '0.500',
860d3652 37 'Test::More' => '0.88',
cc553312 38 'Test::Differences' => '0',
860d3652 39 'Test::Exception' => '0.31',
cb9bbc68 40 'Text::ParseWords' => '0',
6e64adbe 41 },
42};
43
6e64adbe 44
45name 'SQL-Translator';
46author 'Ken Youens-Clark <kclark@cpan.org>';
47abstract 'SQL DDL transformations and more';
c45d3cbc 48license 'perl';
6e64adbe 49
34f636ee 50resources repository => 'https://github.com/dbsrgits/sql-translator/';
51resources bugtracker => 'https://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
52resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
53resources IRC => 'irc://irc.perl.org/#sql-translator';
6e64adbe 54
09d9cd5e 55Meta->{values}{x_authority} = 'cpan:JROBINSON';
56
6e64adbe 57all_from 'lib/SQL/Translator.pm';
c45d3cbc 58readme_from 'lib/SQL/Translator.pm';
6e64adbe 59
60for my $type (qw/requires recommends test_requires/) {
61 no strict qw/refs/;
62 my $f = \&$type;
63 for my $mod (keys %{$deps->{$type} || {} }) {
64 $f->($mod, $deps->{$type}{$mod});
65 }
66}
67
6e64adbe 68install_script (qw|
467b7282 69 script/sqlt-diagram
70 script/sqlt-diff
71 script/sqlt-diff-old
72 script/sqlt-dumper
73 script/sqlt-graph
74 script/sqlt
6e64adbe 75|);
76
77install_share();
78
aee4b66e 79tests_recursive ();
80
81
82# temporary(?) until I get around to fix M::I wrt xt/
83# needs Module::Install::AuthorTests
84eval {
85 # this should not be necessary since the autoloader is supposed
86 # to work, but there were reports of it failing
87 require Module::Install::AuthorTests;
88 recursive_author_tests (qw/xt/);
89 1;
90} || do {
91 if ($Module::Install::AUTHOR) {
92 my $err = $@;
93
94 # better error message in case of missing dep
95 eval { require Module::Install::AuthorTests }
96 || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";
97
98 die $err;
99 }
100};
6e64adbe 101
102auto_install();
103
dc34f950 104if ($Module::Install::AUTHOR) {
105 _recompile_grammars();
106 _recreate_rt_source();
107}
108
6e64adbe 109WriteAll();
dc34f950 110
dc34f950 111sub _recompile_grammars {
0eb3b94a 112 return; # disabled until RT#74593 is resolved
113
bdf60588 114 require File::Spec;
115
116 my $compiled_parser_dir = File::Spec->catdir(qw/
117 share PrecompiledParsers Parse RecDescent DDL SQLT
118 /);
119
120 # Currently consider only single-name parsers containing a grammar marker
121 # This is somewhat fragile, but better than loading all kinds of parsers
122 # to some of which we may not even have the deps
123 my $parser_libdir = 'lib/SQL/Translator/Parser';
124 for my $parser_fn (glob "$parser_libdir/*.pm") {
125 die "$parser_fn does not look like a readable file\n"
126 unless ( -f $parser_fn and -r $parser_fn );
127
128 my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i
129 or die "$parser_fn not named in expected format\n";
130
131 my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> };
132 next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s;
133
134
135 my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm");
136
137 next if (
138 -f $precomp_parser_fn
139 and
140 (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9]
141 );
142
143
144 print "Precompiling parser for $type\n";
145
146 require $parser_fn;
147 require Parse::RecDescent;
148
149 Parse::RecDescent->Precompile(
150 do {
151 no strict 'refs';
152 ${"SQL::Translator::Parser::${type}::GRAMMAR"}
153 || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n"
154 },
155 "Parse::RecDescent::DDL::SQLT::$type"
156 );
157
158 rename( "$type.pm", $precomp_parser_fn )
159 or die "Unable to move $type.pm to $compiled_parser_dir: $!\n";
160 }
161
dc34f950 162}
163
164sub _recreate_rt_source {
165 my $base_xml = "t/data/roundtrip.xml";
166 my $autogen_yaml = "t/data/roundtrip_autogen.yaml";
167
168 print "Updating $autogen_yaml\n";
169
170 unlink $autogen_yaml;
171
172 eval {
173
174 use lib 'lib';
175
176 require SQL::Translator;
177 require SQL::Translator::Parser::XML;
178
179 open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n";
180
181 my $tr = SQL::Translator->new;
182 my $yaml = $tr->translate (
183 parser => 'XML',
184 file => $base_xml,
185 producer => 'YAML',
186 ) or die sprintf ("Unable to translate %s to YAML: %s\n",
187 $base_xml,
188 $tr->error || 'error unknown'
189 );
190
191 print $fh $yaml;
192 close $fh;
193 };
194
195 if ($@) {
16bbaff2 196 die <<EOE;
dc34f950 197
198=========================================================================
d53db6a7 199=============== WARNING !!! =================
dc34f950 200=========================================================================
201
202Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
16bbaff2 203Aborting Makefile generation, please fix the errors indicated below
204(typically by installing the missing modules).
dc34f950 205
d53db6a7 206-------------------------------------------------------------------------
dc34f950 207$@
208
209EOE
dc34f950 210 }
211}