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