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