File Coverage

blib/lib/DBIx/Schema/DSL/Context.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 30 31 96.7


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