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