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

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