| 1 | package Daje::Workflow::GenerateSQL::Script::ForeignKey; | ||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Daje::Workflow::GenerateSQL::Base::Common', -base, -signatures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 1 | has 'tablename' => ""; | |||||||||
| 6 | 1 | has 'created' => 0; | |||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | sub create_foreign_keys($self) { | ||||||||
|
Subroutine
create_foreign_keys: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 9 | 0 | my $fkeys = ''; | |||||||||
| 10 | 0 | $self->templates->{template_fkey} = ""; | |||||||||
| 11 | 0 | $self->templates->{template_ind} = ""; | |||||||||
| 12 | 0 | eval { | |||||||||
| 13 | 0 | my $fields = $self->json->{fields}; | |||||||||
| 14 | 0 | foreach my $key (sort keys %{$fields}) { | |||||||||
| 15 | 0 | ▶ | if (index($key,'_fkey') > -1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | my ($template_fkey,$template_ind) = $self->get_templates($key); | |||||||||
| 17 | 0 | my $referenced_table = substr($key,0,index($key,'_fkey')); | |||||||||
| 18 | 0 | $self->templates->{template_fkey} .= ", " . $template_fkey; | |||||||||
| 19 | 0 | $self->templates->{template_ind} .= " " . $template_ind; | |||||||||
| 20 | 0 | $self->created(1); | |||||||||
| 21 | } | ||||||||||
| 22 | } | ||||||||||
| 23 | }; | ||||||||||
| 24 | 0 | ▶ | $self->error->add_error($@) if defined $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | return; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub get_templates($self, $key) { | ||||||||
|
Subroutine
get_templates: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 0 | my $referenced_table = substr($key,0,index($key,'_fkey')); | |||||||||
| 31 | 0 | my $template_fkey = $self->templates->get_data_section('foreign_key'); | |||||||||
| 32 | 0 | $template_fkey =~ s/<<referenced_table>>/$referenced_table/ig; | |||||||||
| 33 | 0 | my $template_ind = $self->templates->get_data_section('index'); | |||||||||
| 34 | 0 | my $table_name = $self->tablename; | |||||||||
| 35 | 0 | $template_ind =~ s/<<type>>//ig; | |||||||||
| 36 | 0 | $template_ind =~ s/<<table>>/$table_name/ig; | |||||||||
| 37 | 0 | $template_ind =~ s/<<field_names>>/$key/ig; | |||||||||
| 38 | 0 | $template_ind =~ s/<<fields>>/$key/ig; | |||||||||
| 39 | 0 | $self->created(1); | |||||||||
| 40 | |||||||||||
| 41 | 0 | return ($template_fkey,$template_ind); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 1 | 1; | |||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | #################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### | ||||||||||
| 57 | |||||||||||
| 58 | =head1 NAME | ||||||||||
| 59 | |||||||||||
| 60 | Daje::Workflow::GenerateSQL::Script::ForeignKey | ||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | =head1 DESCRIPTION | ||||||||||
| 64 | |||||||||||
| 65 | pod generated by Pod::Autopod - keep this line to make pod updates possible #################### | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | =head1 REQUIRES | ||||||||||
| 69 | |||||||||||
| 70 | L<Mojo::Base> | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | =head1 METHODS | ||||||||||
| 74 | |||||||||||
| 75 | =head2 create_foreign_keys($self) | ||||||||||
| 76 | |||||||||||
| 77 | create_foreign_keys($self)(); | ||||||||||
| 78 | |||||||||||
| 79 | =head2 get_templates($self, | ||||||||||
| 80 | |||||||||||
| 81 | get_templates($self,(); | ||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | =cut | ||||||||||
| 85 | |||||||||||