Commit | Line | Data |
860d3652 |
1 | use inc::Module::Install 1.06; |
6e64adbe |
2 | use strict; |
3 | use warnings; |
4 | |
475a7db7 |
5 | # to deal wuth x.y.z versions properly |
cc553312 |
6 | configure_requires 'ExtUtils::MakeMaker' => '6.54'; |
475a7db7 |
7 | |
860d3652 |
8 | perl_version '5.008001'; |
9 | |
6e64adbe |
10 | my $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 | |
45 | name 'SQL-Translator'; |
46 | author 'Ken Youens-Clark <kclark@cpan.org>'; |
47 | abstract 'SQL DDL transformations and more'; |
c45d3cbc |
48 | license 'perl'; |
6e64adbe |
49 | |
34f636ee |
50 | resources repository => 'https://github.com/dbsrgits/sql-translator/'; |
51 | resources bugtracker => 'https://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator'; |
52 | resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator'; |
53 | resources IRC => 'irc://irc.perl.org/#sql-translator'; |
6e64adbe |
54 | |
09d9cd5e |
55 | Meta->{values}{x_authority} = 'cpan:JROBINSON'; |
56 | |
6e64adbe |
57 | all_from 'lib/SQL/Translator.pm'; |
c45d3cbc |
58 | readme_from 'lib/SQL/Translator.pm'; |
6e64adbe |
59 | |
60 | for 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 |
68 | install_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 | |
77 | install_share(); |
78 | |
aee4b66e |
79 | tests_recursive (); |
80 | |
81 | |
82 | # temporary(?) until I get around to fix M::I wrt xt/ |
83 | # needs Module::Install::AuthorTests |
84 | eval { |
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 | |
102 | auto_install(); |
103 | |
dc34f950 |
104 | if ($Module::Install::AUTHOR) { |
105 | _recompile_grammars(); |
106 | _recreate_rt_source(); |
107 | } |
108 | |
6e64adbe |
109 | WriteAll(); |
dc34f950 |
110 | |
dc34f950 |
111 | sub _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 | |
164 | sub _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 | |
202 | Unable to update the roundtrip schema (attempt triggered by AUTHOR mode). |
16bbaff2 |
203 | Aborting Makefile generation, please fix the errors indicated below |
204 | (typically by installing the missing modules). |
dc34f950 |
205 | |
d53db6a7 |
206 | ------------------------------------------------------------------------- |
dc34f950 |
207 | $@ |
208 | |
209 | EOE |
dc34f950 |
210 | } |
211 | } |