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