blib/lib/blx/xsdsql/xsd_parser/node/choice.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 62 CC 5 SCAR 26.1
CC
5
Cov
0%
trigger_at_start_node
30.0
trigger_at_end_node
2.0
BEGIN
2.0
CRAP 13.7
1 package blx::xsdsql::xsd_parser::node::choice;
2  
3 use strict; # use strict is for PBP
4 use Filter::Include;
5 include blx::xsdsql::include;
6 #line 7
7  
8 use blx::xsdsql::ut::ut qw(nvl);
9 use blx::xsdsql::xsd_parser::type;
10 use base qw(blx::xsdsql::xsd_parser::node);
11  
12 use constant {
13 DEFAULT_OCCURS_TABLE_PREFIX => 'm_'
14 };
15  
16 sub trigger_at_start_node {
17 my ($self,%params)=@_;
18 my $parent_table=$self->_get_parent_table;
19 my $path=$parent_table->get_path;
20 my ($maxoccurs,$minoccurs)=(
21 $self->_resolve_maxOccurs
22 ,$self->_resolve_minOccurs(CHOICE => $parent_table->get_attrs_value(qw(CHOICE)))
23 );
24 if ($maxoccurs > 1) {
25 my $schema=$self->get_attrs_value(qw(STACK))->[1];
26 my $table = $self->get_attrs_value(qw(TABLE_CLASS))->new(
27 NAME => DEFAULT_OCCURS_TABLE_PREFIX.$parent_table->get_attrs_value(qw(NAME))
28 ,MAXOCCURS => $maxoccurs
29 ,CHOICE => 1
30 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
31 );
32
33 $schema->set_table_names($table);
34  
35 $table->add_columns(
36 $schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(ID))
37 ,$schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SEQ))
38 );
39 $parent_table->add_child_tables($table);
40 my $isparent_choice=$parent_table->get_attrs_value(qw(CHOICE));
41  
42 my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new ( #hook the column to the parent table
43 NAME => $table->get_attrs_value(qw(NAME))
44 ,TYPE => $schema->get_attrs_value(qw(ID_SQL_TYPE))
45 ,MINOCCURS => 0
46 ,MAXOCCURS => 1
47 ,PATH_REFERENCE => $table->get_path
48 ,TABLE_REFERENCE => $table
49 ,CHOICE => $isparent_choice
50 ,ELEMENT_FORM => $self->_resolve_form
51 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
52 );
53  
54 if (defined $parent_table->get_xsd_seq) { #the table is a sequence or a choice
55 $column->set_attrs_value(XSD_SEQ => $parent_table->get_xsd_seq);
56 $parent_table->inc_xsd_seq unless $isparent_choice;
57 }
58 $parent_table->add_columns($column);
59 $self->set_attrs_value(TABLE => $table);
60 }
61 else {
62 $parent_table->set_attrs_value(CHOICE => 1);
63 $parent_table->set_attrs_value(XSD_SEQ => 0) unless defined $parent_table->get_xsd_seq;
64 $self->set_attrs_value(TABLE => $parent_table);
65 }
66 }
67  
68 sub trigger_at_end_node {
69 my ($self,%params)=@_;
70 my $parent_table=$self->get_attrs_value(qw(STACK))->[-1]->get_attrs_value(qw(TABLE));
71 $parent_table->inc_xsd_seq;
72 return $self;
73 }
74  
75  
76 1;
77  
78  
79  
80 __END__