| 1 | package DBIO::Schema::ModelCompiler; | ||||||||||
| 2 | # ABSTRACT: compile a base-type schema into one engine's native target model | ||||||||||
| 3 | |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | our $VERSION = '0.900007'; | |||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use DBIO::Schema::Type (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 15 | 1 | my ($class, %args) = @_; | |||||||||
| 16 | 1 | ▶ | croak "adapter required" unless $args{adapter}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | bless { %args }, $class; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | sub adapter { $_[0]->{adapter} } | ||||||||
|
Subroutine
adapter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub compile { | ||||||||
|
Subroutine
compile: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 25 | 1 | my ($self, $schema) = @_; | |||||||||
| 26 | 1 | my $adapter = $self->adapter; | |||||||||
| 27 | 1 | my %tables; | |||||||||
| 28 | |||||||||||
| 29 | 1 | for my $moniker ($schema->sources) { | |||||||||
| 30 | 1 | my $source = $schema->source($moniker); | |||||||||
| 31 | 1 | my $name = $source->name; | |||||||||
| 32 | 1 | ▶ | next if ref $name; # skip virtual views (scalar-ref name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 1 | my $info = $source->columns_info; | |||||||||
| 35 | 1 | my %is_pk = map { $_ => 1 } $source->primary_columns; | |||||||||
| 36 | |||||||||||
| 37 | 1 | my @columns; | |||||||||
| 38 | 1 | for my $col_name ($source->columns) { | |||||||||
| 39 | 7 | my $canon = DBIO::Schema::Type::canonical_column($col_name, $info->{$col_name}); | |||||||||
| 40 | push @columns, { | ||||||||||
| 41 | column_name => $col_name, | ||||||||||
| 42 | native_type => $adapter->to_native($canon), | ||||||||||
| 43 | not_null => $canon->{not_null}, | ||||||||||
| 44 | default => $canon->{default}, | ||||||||||
| 45 | is_pk => ($is_pk{$col_name} ? 1 : 0), | ||||||||||
| 46 | auto_increment => $canon->{auto_increment}, | ||||||||||
| 47 | 7 | ▶ | }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | $tables{$name} = { | |||||||||
| 51 | table_name => $name, | ||||||||||
| 52 | columns => \@columns, | ||||||||||
| 53 | primary_key => [ $source->primary_columns ], | ||||||||||
| 54 | }; | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | return { tables => \%tables }; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 3 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||