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

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