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