blib/lib/DBIO/Schema/ModelCompiler.pm

filter: Statementstmt 100% 37 / 37 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 96.3% 52 / 54 CC 6 SCAR 9.9
CC
6
Cov
95%
compile
5.0
new
2.0
BEGIN
1.0
CRAP 2.7
« blib/lib/DBIO/Test/Slow.pm ↑ Summary blib/lib/DBIO/Storage/DBI/IdentityInsert.pm »
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
BranchTrueFalseTotal
unless $args{"adapter"} 0 1 1
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
BranchTrueFalseTotal
if ref $name 0 1 1
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
BranchTrueFalseTotal
$is_pk{$col_name} ? : 1 6 7
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__
« blib/lib/DBIO/Test/Slow.pm ↑ Summary blib/lib/DBIO/Storage/DBI/IdentityInsert.pm »