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