File: Makefile.PL

package info (click to toggle)
libsql-translator-perl 0.11024-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 4,572 kB
  • sloc: perl: 67,471; sql: 3,809; xml: 258; makefile: 2
file content (211 lines) | stat: -rw-r--r-- 5,776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
BEGIN { push @INC, '.' unless $INC[-1] eq '.' }
use inc::Module::Install 1.06;
use strict;
use warnings;

# to deal wuth x.y.z versions properly
configure_requires 'ExtUtils::MakeMaker' => '6.54';

perl_version '5.008001';

my $deps = {
  requires => {
    'Digest::SHA'              => '0',
    'Carp::Clan'               => '0',
    'Parse::RecDescent'        => '1.967009',
    'DBI'                      => '1.54',
    'File::ShareDir'           => '1.0',
    'Moo'                      => '1.000003',
    'Package::Variant'         => '1.001001',
    'Sub::Quote'               => '0',
    'Try::Tiny'                => '0.04',
    'Scalar::Util'             => '0',
  },
  recommends => {
    'Template'                 => '2.20',
    'GD'                       => '0',
    'GraphViz'                 => '0',
    'Graph::Directed'          => '0',
    'Spreadsheet::ParseExcel'  => '0.41',
    'Text::RecordParser'       => '0.02',
    'XML::LibXML'              => '1.69',
  },
  test_requires => {
    'JSON'                     => '2.0',
    'YAML'                     => '0.66',
    'XML::Writer'              => '0.500',
    'Test::More'               => '0.88',
    'Test::Differences'        => '0',
    'Test::Exception'          => '0.31',
    'Text::ParseWords'         => '0',
  },
};


name        'SQL-Translator';
author      'Ken Youens-Clark <kclark@cpan.org>';
abstract    'SQL DDL transformations and more';
license     'perl';

resources    repository => 'https://github.com/dbsrgits/sql-translator/';
resources    bugtracker => 'https://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
resources    Ratings    => 'http://cpanratings.perl.org/d/SQL-Translator';
resources    IRC        => 'irc://irc.perl.org/#sql-translator';

Meta->{values}{x_authority} = 'cpan:JROBINSON';

all_from    'lib/SQL/Translator.pm';
readme_from 'lib/SQL/Translator.pm';

for my $type (qw/requires recommends test_requires/) {
  no strict qw/refs/;
  my $f = \&$type;
  for my $mod (sort keys %{$deps->{$type} || {} }) {
    $f->($mod, $deps->{$type}{$mod});
  }
}

install_script (qw|
  script/sqlt-diagram
  script/sqlt-diff
  script/sqlt-diff-old
  script/sqlt-dumper
  script/sqlt-graph
  script/sqlt
|);

install_share();

tests_recursive ();


# temporary(?) until I get around to fix M::I wrt xt/
# needs Module::Install::AuthorTests
eval {
  # this should not be necessary since the autoloader is supposed
  # to work, but there were reports of it failing
  require Module::Install::AuthorTests;
  recursive_author_tests (qw/xt/);
  1;
} || do {
  if ($Module::Install::AUTHOR) {
    my $err = $@;

    # better error message in case of missing dep
    eval { require Module::Install::AuthorTests }
      || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";

    die $err;
  }
};

auto_install();

if ($Module::Install::AUTHOR) {
  _recompile_grammars();
  _recreate_rt_source();
}

WriteAll();

sub _recompile_grammars {
  return; # disabled until RT#74593 is resolved

  require File::Spec;

  my $compiled_parser_dir = File::Spec->catdir(qw/
    share PrecompiledParsers Parse RecDescent DDL SQLT
  /);

  # Currently consider only single-name parsers containing a grammar marker
  # This is somewhat fragile, but better than loading all kinds of parsers
  # to some of which we may not even have the deps
  my $parser_libdir = 'lib/SQL/Translator/Parser';
  for my $parser_fn (glob "$parser_libdir/*.pm") {
    die "$parser_fn does not look like a readable file\n"
      unless ( -f $parser_fn and -r $parser_fn );

    my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i
      or die "$parser_fn not named in expected format\n";

    my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> };
    next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s;


    my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm");

    next if (
      -f $precomp_parser_fn
        and
      (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9]
    );


    print "Precompiling parser for $type\n";

    require $parser_fn;
    require Parse::RecDescent;

    Parse::RecDescent->Precompile(
      do {
        no strict 'refs';
        ${"SQL::Translator::Parser::${type}::GRAMMAR"}
          || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n"
      },
      "Parse::RecDescent::DDL::SQLT::$type"
    );

    rename( "$type.pm", $precomp_parser_fn )
      or die "Unable to move $type.pm to $compiled_parser_dir: $!\n";
  }

}

sub _recreate_rt_source {
  my $base_xml = "t/data/roundtrip.xml";
  my $autogen_yaml = "t/data/roundtrip_autogen.yaml";

  print "Updating $autogen_yaml\n";

  unlink $autogen_yaml;

  eval {

    use lib 'lib';

    require SQL::Translator;
    require SQL::Translator::Parser::XML;

    open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n";

    my $tr = SQL::Translator->new;
    my $yaml = $tr->translate (
      parser => 'XML',
      file => $base_xml,
      producer => 'YAML',
    ) or  die sprintf ("Unable to translate %s to YAML: %s\n",
              $base_xml,
              $tr->error || 'error unknown'
          );

    print $fh $yaml;
    close $fh;
  };

  if ($@) {
    die <<EOE;

=========================================================================
===============              WARNING !!!                =================
=========================================================================

Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
Aborting Makefile generation, please fix the errors indicated below
(typically by installing the missing modules).

-------------------------------------------------------------------------
$@

EOE
  }
}