Commit | Line | Data |
afae491f |
1 | BEGIN { push @INC, '.' unless $INC[-1] eq '.' } |
860d3652 |
2 | use inc::Module::Install 1.06; |
6e64adbe |
3 | use strict; |
4 | use warnings; |
5 | |
475a7db7 |
6 | # to deal wuth x.y.z versions properly |
cc553312 |
7 | configure_requires 'ExtUtils::MakeMaker' => '6.54'; |
475a7db7 |
8 | |
860d3652 |
9 | perl_version '5.008001'; |
10 | |
6e64adbe |
11 | my $deps = { |
12 | requires => { |
cc553312 |
13 | 'Digest::SHA' => '0', |
14 | 'Carp::Clan' => '0', |
7e666ece |
15 | 'Parse::RecDescent' => '1.967009', |
cf915bd8 |
16 | 'DBI' => '1.54', |
cc553312 |
17 | 'File::ShareDir' => '1.0', |
a5bfeba8 |
18 | 'Moo' => '1.000003', |
0fb58589 |
19 | 'Package::Variant' => '1.001001', |
68d75205 |
20 | 'Sub::Quote' => '0', |
45287c81 |
21 | 'Try::Tiny' => '0.04', |
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'; |
58 | |
59 | for my $type (qw/requires recommends test_requires/) { |
60 | no strict qw/refs/; |
61 | my $f = \&$type; |
c1f9a59d |
62 | for my $mod (sort keys %{$deps->{$type} || {} }) { |
6e64adbe |
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 | |
b43ba76c |
80 | if ($Module::Install::AUTHOR) { |
81 | my @missing_plugins; |
82 | for my $plugin (qw(AuthorTests ReadmeFromPod)) { |
83 | unless (eval "require Module::Install::$plugin; 1") { |
84 | push @missing_plugins, "Module::Install::$plugin"; |
85 | chomp(my $err = $@); |
86 | $missing_plugins[-1] .= " ($err)" |
87 | unless $err =~ m{^Can't locate Module/Install/$plugin\.pm in \@INC}; |
88 | } |
89 | } |
90 | die "\nYou need to install the following modules to run this Makefile.PL in author mode:\n\n", join("\n", @missing_plugins), "\n\n" |
91 | if @missing_plugins; |
92 | |
93 | recursive_author_tests (qw/xt/); |
94 | readme_from('lib/SQL/Translator.pm'); |
95 | } |
6e64adbe |
96 | |
97 | auto_install(); |
98 | |
dc34f950 |
99 | if ($Module::Install::AUTHOR) { |
100 | _recompile_grammars(); |
101 | _recreate_rt_source(); |
102 | } |
103 | |
6e64adbe |
104 | WriteAll(); |
dc34f950 |
105 | |
dc34f950 |
106 | sub _recompile_grammars { |
0eb3b94a |
107 | return; # disabled until RT#74593 is resolved |
108 | |
bdf60588 |
109 | require File::Spec; |
110 | |
111 | my $compiled_parser_dir = File::Spec->catdir(qw/ |
112 | share PrecompiledParsers Parse RecDescent DDL SQLT |
113 | /); |
114 | |
115 | # Currently consider only single-name parsers containing a grammar marker |
116 | # This is somewhat fragile, but better than loading all kinds of parsers |
117 | # to some of which we may not even have the deps |
118 | my $parser_libdir = 'lib/SQL/Translator/Parser'; |
119 | for my $parser_fn (glob "$parser_libdir/*.pm") { |
120 | die "$parser_fn does not look like a readable file\n" |
121 | unless ( -f $parser_fn and -r $parser_fn ); |
122 | |
123 | my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i |
124 | or die "$parser_fn not named in expected format\n"; |
125 | |
126 | my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> }; |
127 | next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s; |
128 | |
129 | |
130 | my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm"); |
131 | |
132 | next if ( |
133 | -f $precomp_parser_fn |
134 | and |
135 | (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9] |
136 | ); |
137 | |
138 | |
139 | print "Precompiling parser for $type\n"; |
140 | |
141 | require $parser_fn; |
142 | require Parse::RecDescent; |
143 | |
144 | Parse::RecDescent->Precompile( |
145 | do { |
146 | no strict 'refs'; |
147 | ${"SQL::Translator::Parser::${type}::GRAMMAR"} |
148 | || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n" |
149 | }, |
150 | "Parse::RecDescent::DDL::SQLT::$type" |
151 | ); |
152 | |
153 | rename( "$type.pm", $precomp_parser_fn ) |
154 | or die "Unable to move $type.pm to $compiled_parser_dir: $!\n"; |
155 | } |
156 | |
dc34f950 |
157 | } |
158 | |
159 | sub _recreate_rt_source { |
160 | my $base_xml = "t/data/roundtrip.xml"; |
161 | my $autogen_yaml = "t/data/roundtrip_autogen.yaml"; |
162 | |
163 | print "Updating $autogen_yaml\n"; |
164 | |
165 | unlink $autogen_yaml; |
166 | |
167 | eval { |
168 | |
169 | use lib 'lib'; |
170 | |
171 | require SQL::Translator; |
172 | require SQL::Translator::Parser::XML; |
173 | |
174 | open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n"; |
175 | |
176 | my $tr = SQL::Translator->new; |
177 | my $yaml = $tr->translate ( |
178 | parser => 'XML', |
179 | file => $base_xml, |
180 | producer => 'YAML', |
181 | ) or die sprintf ("Unable to translate %s to YAML: %s\n", |
182 | $base_xml, |
183 | $tr->error || 'error unknown' |
184 | ); |
185 | |
186 | print $fh $yaml; |
187 | close $fh; |
188 | }; |
189 | |
190 | if ($@) { |
16bbaff2 |
191 | die <<EOE; |
dc34f950 |
192 | |
193 | ========================================================================= |
d53db6a7 |
194 | =============== WARNING !!! ================= |
dc34f950 |
195 | ========================================================================= |
196 | |
197 | Unable to update the roundtrip schema (attempt triggered by AUTHOR mode). |
16bbaff2 |
198 | Aborting Makefile generation, please fix the errors indicated below |
199 | (typically by installing the missing modules). |
dc34f950 |
200 | |
d53db6a7 |
201 | ------------------------------------------------------------------------- |
dc34f950 |
202 | $@ |
203 | |
204 | EOE |
dc34f950 |
205 | } |
206 | } |