Moo port makes both of these no longer needed
[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     'Digest::SHA'              => '0',
13     'Carp::Clan'               => '0',
14     'IO::Scalar'               => '2.110',
15     'Parse::RecDescent'        => '1.967009',
16     'DBI'                      => '0',
17     'File::ShareDir'           => '1.0',
18     'File::Spec'               => '0',
19     'XML::Writer'              => '0.500',
20     'Moo'                      => '1.000003',
21     'Package::Variant'         => '1.001001',
22     'Sub::Quote'               => '0',
23     'Try::Tiny'                => '0.04',
24     'List::MoreUtils'          => '0.09',
25   },
26   recommends => {
27     'Template'                 => '2.20',
28     'GD'                       => '0',
29     'GraphViz'                 => '0',
30     'Graph::Directed'          => '0',
31     'Spreadsheet::ParseExcel'  => '0.41',
32     'Text::ParseWords'         => '0',
33     'Text::RecordParser'       => '0.02',
34     'XML::LibXML'              => '1.69',
35   },
36   test_requires => {
37     'YAML'                     => '0.66',
38     'Test::More'               => '0.88',
39     'Test::Differences'        => '0',
40     'Test::Exception'          => '0.31',
41   },
42 };
43
44
45 name        'SQL-Translator';
46 author      'Ken Youens-Clark <kclark@cpan.org>';
47 abstract    'SQL DDL transformations and more';
48 license     'gpl';
49 repository  'git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git';
50 bugtracker  'http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
51
52 resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
53
54 Meta->{values}{x_authority} = 'cpan:JROBINSON';
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
66 install_script (qw|
67   script/sqlt-diagram
68   script/sqlt-diff
69   script/sqlt-diff-old
70   script/sqlt-dumper
71   script/sqlt-graph
72   script/sqlt
73 |);
74
75 install_share();
76
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 };
99
100 auto_install();
101
102 if ($Module::Install::AUTHOR) {
103   _recompile_grammars();
104   _recreate_rt_source();
105 }
106
107 WriteAll();
108
109 sub _recompile_grammars {
110   return; # disabled until RT#74593 is resolved
111
112   require File::Spec;
113
114   my $compiled_parser_dir = File::Spec->catdir(qw/
115     share PrecompiledParsers Parse RecDescent DDL SQLT
116   /);
117
118   # Currently consider only single-name parsers containing a grammar marker
119   # This is somewhat fragile, but better than loading all kinds of parsers
120   # to some of which we may not even have the deps
121   my $parser_libdir = 'lib/SQL/Translator/Parser';
122   for my $parser_fn (glob "$parser_libdir/*.pm") {
123     die "$parser_fn does not look like a readable file\n"
124       unless ( -f $parser_fn and -r $parser_fn );
125
126     my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i
127       or die "$parser_fn not named in expected format\n";
128
129     my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> };
130     next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s;
131
132
133     my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm");
134
135     next if (
136       -f $precomp_parser_fn
137         and
138       (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9]
139     );
140
141
142     print "Precompiling parser for $type\n";
143
144     require $parser_fn;
145     require Parse::RecDescent;
146
147     Parse::RecDescent->Precompile(
148       do {
149         no strict 'refs';
150         ${"SQL::Translator::Parser::${type}::GRAMMAR"}
151           || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n"
152       },
153       "Parse::RecDescent::DDL::SQLT::$type"
154     );
155
156     rename( "$type.pm", $precomp_parser_fn )
157       or die "Unable to move $type.pm to $compiled_parser_dir: $!\n";
158   }
159
160 }
161
162 sub _recreate_rt_source {
163   my $base_xml = "t/data/roundtrip.xml";
164   my $autogen_yaml = "t/data/roundtrip_autogen.yaml";
165
166   print "Updating $autogen_yaml\n";
167
168   unlink $autogen_yaml;
169
170   eval {
171
172     use lib 'lib';
173
174     require SQL::Translator;
175     require SQL::Translator::Parser::XML;
176
177     open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n";
178
179     my $tr = SQL::Translator->new;
180     my $yaml = $tr->translate (
181       parser => 'XML',
182       file => $base_xml,
183       producer => 'YAML',
184     ) or  die sprintf ("Unable to translate %s to YAML: %s\n",
185               $base_xml,
186               $tr->error || 'error unknown'
187           );
188
189     print $fh $yaml;
190     close $fh;
191   };
192
193   if ($@) {
194     warn <<EOE;
195
196 =========================================================================
197 ===============              WARNING !!!                =================
198 =========================================================================
199
200 Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
201 We will still generate a Makefile, but be aware that if you build a dist
202 this way, it *WILL* be broken.
203
204 -------------------------------------------------------------------------
205 $@
206
207 Press Enter to continue.
208 EOE
209   <>;
210   }
211 }