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