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