blib/lib/SQL/Translator/Parser/YAML.pm

filter: Statementstmt 86.2% 69 / 80 Branchbran 58.3% 14 / 24 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 81.8% 99 / 121 CC 23 SCAR 31.7
CC
23
Cov
81%
parse
29.7
BEGIN
1.0
BEGIN
1.0
CRAP 23.8
« 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
BranchTrueFalseTotal
if $translator->debug 0 25 25
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
l!l
604
MC/DC100%1/1
$data->{'tables'}{$_}{'order'} || 0
$data->{'tables'}{$_}{'order'}
Truth table100%2/2
A
A= $data->{'tables'}{$_}{'order'}
Aresult
11
00
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
BranchTrueFalseTotal
my $table = $schema->add_table(map({$tdata->{$_} ? ($_, $tdata->{$_}) : ();} "name", "extra", "options")) or die $schema->error 64 0 64
$tdata->{$_} ? : 110 82 192
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
BranchTrueFalseTotal
$table->add_field(%$fdata) or die $table->error 200 0 200
41 $table->primary_key($fdata->{'name'})
42 200 ▶ if $fdata->{'is_primary_key'};
Branch: 1 branch
BranchTrueFalseTotal
if $fdata->{"is_primary_key"} 57 143 200
43 }
44  
45 64 ▶ for my $idata (@{ $tdata->{'indices'} || [] }) {
Condition100%2/2
$tdata->{'indices'} || []
l!l
4321
MC/DC100%1/1
$tdata->{'indices'} || []
$tdata->{'indices'}
Truth table100%2/2
A
A= $tdata->{'indices'}
Aresult
11
00
46 21 ▶ $table->add_index(%$idata) or die $table->error;
Branch: 1 branch
BranchTrueFalseTotal
$table->add_index(%$idata) or die $table->error 21 0 21
47 }
48  
49 64 ▶ for my $cdata (@{ $tdata->{'constraints'} || [] }) {
Condition100%2/2
$tdata->{'constraints'} || []
l!l
5113
MC/DC100%1/1
$tdata->{'constraints'} || []
$tdata->{'constraints'}
Truth table100%2/2
A
A= $tdata->{'constraints'}
Aresult
11
00
50 84 ▶ $table->add_constraint(%$cdata) or die $table->error;
Branch: 1 branch
BranchTrueFalseTotal
$table->add_constraint(%$cdata) or die $table->error 84 0 84
51 }
52  
53 $table->comments($tdata->{'comments'})
54 64 ▶ if exists $tdata->{'comments'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tdata->{"comments"} 0 64 64
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
BranchTrueFalseTotal
$schema->add_view(%$vdata) or die $schema->error 3 0 3
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
BranchTrueFalseTotal
$schema->add_trigger(%$tdata) or die $schema->error 9 0 9
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
BranchTrueFalseTotal
$schema->add_procedure(%$tdata) or die $schema->error 3 0 3
91 }
92  
93 25 ▶ if (my $tr_data = $data->{'translator'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tr_data = $data->{"translator"}) 0 25 25
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__
« blib/lib/SQL/Translator/Parser/XML/SQLFairy.pm ↑ Summary blib/lib/SQL/Translator/Producer/TT/Table.pm »