| 1 | package DBIx::Schema::DSL::Context; | ||||||||||
| 2 | 8 | ▶ | use 5.008_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use Clone qw/clone/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use SQL::Translator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | has name => ( | |||||||||
| 11 | is => 'rw', | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | has db => ( | ||||||||||
| 15 | is => 'rw', | ||||||||||
| 16 | 12 | ▶ | default => sub {'MySQL'}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 8 | ); | |||||||||
| 18 | |||||||||||
| 19 | has translator => ( | ||||||||||
| 20 | is => 'lazy', | ||||||||||
| 21 | default => sub { | ||||||||||
| 22 | 9 | ▶ | SQL::Translator->new; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | }, | ||||||||||
| 24 | 8 | ); | |||||||||
| 25 | |||||||||||
| 26 | has schema => ( | ||||||||||
| 27 | is => 'lazy', | ||||||||||
| 28 | default => sub { | ||||||||||
| 29 | 9 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 9 | $self->translator->schema->name($self->name); | |||||||||
| 31 | 9 | $self->translator->schema->database($self->db); | |||||||||
| 32 | 9 | $self->translator->schema; | |||||||||
| 33 | }, | ||||||||||
| 34 | 8 | ); | |||||||||
| 35 | |||||||||||
| 36 | 8 | has _creating_table => ( | |||||||||
| 37 | is => 'rw', | ||||||||||
| 38 | clearer => '_clear_creating_table', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | has translate => ( | ||||||||||
| 42 | is => 'lazy', | ||||||||||
| 43 | default => sub { | ||||||||||
| 44 | 7 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 45 | 7 | my $output = $self->translator->translate(to => $self->db); | |||||||||
| 46 | # ignore initial comments. | ||||||||||
| 47 | 7 | ▶ | 1 while $output =~ s/\A--.*?\r?\n//ms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 7 | $output; | |||||||||
| 49 | }, | ||||||||||
| 50 | 8 | ); | |||||||||
| 51 | |||||||||||
| 52 | has table_extra => ( | ||||||||||
| 53 | is => 'lazy', | ||||||||||
| 54 | writer => 'set_table_extra', | ||||||||||
| 55 | default => sub { | ||||||||||
| 56 | 9 | ▶ | shift->db eq 'MySQL' ? { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 57 | mysql_table_type => 'InnoDB', | ||||||||||
| 58 | mysql_charset => 'utf8', | ||||||||||
| 59 | } : {}; | ||||||||||
| 60 | }, | ||||||||||
| 61 | 8 | ); | |||||||||
| 62 | |||||||||||
| 63 | 8 | has default_unsigned => ( | |||||||||
| 64 | is => 'rw', | ||||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | 8 | has default_not_null => ( | |||||||||
| 68 | is => 'rw', | ||||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | has no_fk_translator => ( | ||||||||||
| 72 | is => 'lazy', | ||||||||||
| 73 | default => sub { | ||||||||||
| 74 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 75 | 2 | my $no_fk_translator = clone $self->translator; | |||||||||
| 76 | |||||||||||
| 77 | 2 | for my $table ($no_fk_translator->schema->get_tables) { | |||||||||
| 78 | 8 | $table->drop_constraint($_) for $table->fkey_constraints; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 2 | $no_fk_translator; | |||||||||
| 82 | }, | ||||||||||
| 83 | 8 | ); | |||||||||
| 84 | |||||||||||
| 85 | has no_fk_translate => ( | ||||||||||
| 86 | is => 'lazy', | ||||||||||
| 87 | default => sub { | ||||||||||
| 88 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 89 | 2 | my $output = $self->no_fk_translator->translate(to => $self->db); | |||||||||
| 90 | # ignore initial comments. | ||||||||||
| 91 | 2 | ▶ | 1 while $output =~ s/\A--.*?\r?\n//ms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 2 | $output; | |||||||||
| 93 | }, | ||||||||||
| 94 | 8 | ); | |||||||||
| 95 | |||||||||||
| 96 | has default_varchar_size => ( | ||||||||||
| 97 | is => 'rw', | ||||||||||
| 98 | 12 | ▶ | default => sub { 255 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 99 | 8 | ); | |||||||||
| 100 | |||||||||||
| 101 | 8 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 102 | |||||||||||
| 103 | sub _creating_table_name { | ||||||||||
| 104 | shift->_creating_table->{table_name} | ||||||||||
| 105 | 2 | ▶ | or die 'Not in create_table block.'; | ||||||||
|
Subroutine
_creating_table_name: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 8 | 1; | |||||||||