« blib/lib/SQL/Translator/Parser/XML/SQLFairy.pm
↑ Summary
blib/lib/SQL/Translator/Producer/TT/Table.pm »
| 1 | package SQL::Translator::Parser::YAML; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 17 | our $VERSION = '1.66'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 17 | ▶ | use SQL::Translator::Schema; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 17 | ▶ | use SQL::Translator::Utils qw(header_comment); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 17 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 17 | ▶ | use YAML qw(Load); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 25 | ▶ | sub parse { | ||||||||||||
|
Subroutine
parse: called CC=23 SCAR=33.9
Pod
undocumented
| |||||||||||||||
| 13 | 25 | my ($translator, $data) = @_; | |||||||||||||
| 14 | 25 | $data = Load($data); | |||||||||||||
| 15 | 25 | $data = $data->{'schema'}; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 25 | ▶ | warn "YAML data:", Dumper($data) if $translator->debug; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 25 | my $schema = $translator->schema; | |||||||||||||
| 20 | |||||||||||||||
| 21 | # | ||||||||||||||
| 22 | # Tables | ||||||||||||||
| 23 | # | ||||||||||||||
| 24 | 64 | my @tables = map { $data->{'tables'}{ $_->[1] } } | |||||||||||||
| 25 | 57 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 26 | 64 | ▶ | map { [ $data->{'tables'}{$_}{'order'} || 0, $_ ] } | ||||||||||||
|
Condition100%2/2
$data->{'tables'}{$_}{'order'} || 0
MC/DC100%1/1
$data->{'tables'}{$_}{'order'} || 0
$data->{'tables'}{$_}{'order'}
Truth table100%2/2
A
A= $data->{'tables'}{$_}{'order'}
| |||||||||||||||
| 27 | 25 | keys %{ $data->{'tables'} }; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 25 | for my $tdata (@tables) { | |||||||||||||
| 30 | |||||||||||||||
| 31 | 64 | ▶ | my $table = $schema->add_table(map { $tdata->{$_} ? ($_ => $tdata->{$_}) : () } (qw/name extra options/)) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | or die $schema->error; | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 200 | my @fields = map { $tdata->{'fields'}{ $_->[1] } } | |||||||||||||
| 35 | 262 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 36 | 200 | map { [ $tdata->{'fields'}{$_}{'order'}, $_ ] } | |||||||||||||
| 37 | 64 | keys %{ $tdata->{'fields'} }; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 64 | for my $fdata (@fields) { | |||||||||||||
| 40 | 200 | ▶ | $table->add_field(%$fdata) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | $table->primary_key($fdata->{'name'}) | ||||||||||||||
| 42 | 200 | ▶ | if $fdata->{'is_primary_key'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 64 | ▶ | for my $idata (@{ $tdata->{'indices'} || [] }) { | ||||||||||||
|
Condition100%2/2
$tdata->{'indices'} || []
MC/DC100%1/1
$tdata->{'indices'} || []
$tdata->{'indices'}
Truth table100%2/2
A
A= $tdata->{'indices'}
| |||||||||||||||
| 46 | 21 | ▶ | $table->add_index(%$idata) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 64 | ▶ | for my $cdata (@{ $tdata->{'constraints'} || [] }) { | ||||||||||||
|
Condition100%2/2
$tdata->{'constraints'} || []
MC/DC100%1/1
$tdata->{'constraints'} || []
$tdata->{'constraints'}
Truth table100%2/2
A
A= $tdata->{'constraints'}
| |||||||||||||||
| 50 | 84 | ▶ | $table->add_constraint(%$cdata) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | $table->comments($tdata->{'comments'}) | ||||||||||||||
| 54 | 64 | ▶ | if exists $tdata->{'comments'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | # | ||||||||||||||
| 58 | # Views | ||||||||||||||
| 59 | # | ||||||||||||||
| 60 | 3 | my @views = map { $data->{'views'}{ $_->[1] } } | |||||||||||||
| 61 | 0 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 62 | 3 | map { [ $data->{'views'}{$_}{'order'}, $_ ] } | |||||||||||||
| 63 | 25 | keys %{ $data->{'views'} }; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 25 | for my $vdata (@views) { | |||||||||||||
| 66 | 3 | ▶ | $schema->add_view(%$vdata) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | # | ||||||||||||||
| 70 | # Triggers | ||||||||||||||
| 71 | # | ||||||||||||||
| 72 | 9 | my @triggers = map { $data->{'triggers'}{ $_->[1] } } | |||||||||||||
| 73 | 8 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 74 | 9 | map { [ $data->{'triggers'}{$_}{'order'}, $_ ] } | |||||||||||||
| 75 | 25 | keys %{ $data->{'triggers'} }; | |||||||||||||
| 76 | |||||||||||||||
| 77 | 25 | for my $tdata (@triggers) { | |||||||||||||
| 78 | 9 | ▶ | $schema->add_trigger(%$tdata) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | # | ||||||||||||||
| 82 | # Procedures | ||||||||||||||
| 83 | # | ||||||||||||||
| 84 | 3 | my @procedures = map { $data->{'procedures'}{ $_->[1] } } | |||||||||||||
| 85 | 0 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 86 | 3 | map { [ $data->{'procedures'}{$_}{'order'}, $_ ] } | |||||||||||||
| 87 | 25 | keys %{ $data->{'procedures'} }; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 25 | for my $tdata (@procedures) { | |||||||||||||
| 90 | 3 | ▶ | $schema->add_procedure(%$tdata) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 25 | ▶ | if (my $tr_data = $data->{'translator'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 0 | $translator->add_drop_table($tr_data->{'add_drop_table'}); | |||||||||||||
| 95 | 0 | $translator->filename($tr_data->{'filename'}); | |||||||||||||
| 96 | 0 | $translator->no_comments($tr_data->{'no_comments'}); | |||||||||||||
| 97 | 0 | $translator->parser_args($tr_data->{'parser_args'}); | |||||||||||||
| 98 | 0 | $translator->producer_args($tr_data->{'producer_args'}); | |||||||||||||
| 99 | 0 | $translator->parser_type($tr_data->{'parser_type'}); | |||||||||||||
| 100 | 0 | $translator->producer_type($tr_data->{'producer_type'}); | |||||||||||||
| 101 | 0 | $translator->show_warnings($tr_data->{'show_warnings'}); | |||||||||||||
| 102 | 0 | $translator->trace($tr_data->{'trace'}); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 25 | return 1; | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | 17 | 1; | |||||||||||||
| 109 | |||||||||||||||
| 110 | __END__ | ||||||||||||||