blib/lib/DBIx/Class/Schema/Loader/Dynamic.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 50.0% 6 / 12 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 72.2% 13 / 18 Podpod 100% 1 / 1 totaltotal 79.6% 86 / 108 CC 17 SCAR 16.2
CC
17
Cov
85%
_load_tables
11.2
new
6.4
_dbic_stmt
2.0
CRAP 5.1
↑ Summary
1 package DBIx::Class::Schema::Loader::Dynamic;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw/DBIx::Class::Schema::Loader::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.05';
11  
12 1 ▶sub new {
Subroutine new: called CC=6 SCAR=18.5
Pod documented
13 1 my ($self, %args) = @_;
14 1 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
15  
16 1 ▶ $args{dump_directory} ||= '/die/if/I/get/used';
Condition50%1/2
$args{"dump_directory"} ||= "/die/if/I/get/used"
l!l
01
MC/DC0%0/1
$args{"dump_directory"} ||= "/die/if/I/get/used"
$args{"dump_directory"}
Truth table50%1/2
A
A= $args{"dump_directory"}
Aresult
11
00
17 1 ▶ $args{left_base_classes} ||= ['DBIx::Class::Core'];
Condition50%1/2
$args{"left_base_classes"} ||= ["DBIx::Class::Core"]
l!l
10
MC/DC0%0/1
$args{"left_base_classes"} ||= ["DBIx::Class::Core"]
$args{"left_base_classes"}
Truth table50%1/2
A
A= $args{"left_base_classes"}
Aresult
11
00
18  
19 1 my $new = $self->next::method(%args);
20  
21 # The loader 'factory' returns a more engine-specific subclass, e.g. DBIC:S:L::DBI::Pg. So,
22 # I'll have what she's having..
23 {
24 1 my $isa = $class . "::ISA";
25 1 ▶ no strict 'refs'; @$isa = (ref $new);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 }
27  
28 1 ▶ eval("require $_") || die for @{$new->left_base_classes};
Branch: 1 branch
BranchTrueFalseTotal
eval "require $_" or die 1 0 1
29 1 bless $new, $class;
30 }
31  
32 1 ▶sub _load_tables {
Subroutine _load_tables: called CC=10 SCAR=24.1
33 1 my ($self, @tables) = @_;
34  
35 # Save the new tables to the tables list and compute monikers
36 1 foreach (@tables) {
37 3 $self->_tables->{$_->sql_name} = $_;
38 3 $self->monikers->{$_->sql_name} = $self->_table2moniker($_);
39 }
40  
41 # "check for moniker clashes": NEED TO FACTOR OUT THIS ALGORITHM FROM ::Base. leave it out for now.
42  
43 1 $self->_make_src_class($_) for @tables;
44 1 $self->_setup_src_meta($_) for @tables;
45  
46 # Here's the "Rinse-and-Repeat" Catch-22 that causes so much dbics::loader agony:
47 # - 'register_class' freezes what we know about the class so far.
48 # - relationships cannot be dynamically added until classes are registered.
49 # Solution: register all classes while still unrelated, then build relationships, then wipe-and-reregister.
50  
51 1 for my $table (@tables) {
52 3 my $moniker = $self->monikers->{$table->sql_name};
53 3 my $class = $self->classes->{$table->sql_name};
54 3 $self->schema->register_class($moniker=>$class);
55 }
56  
57 1 $self->_load_relationships(\@tables);
58  
59 # load user-defined customisations as 'mix-ins' if present.
60 1 for my $class (sort values %{$self->classes}) {
61 3 ▶ if (eval "require $class") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $class") 0 3 3
62 0 ▶ printf STDERR "$class customisations loaded\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
63 next
64 0 }
65 3 my $err = $@;
66 3 ▶ next if $err =~ /Can't locate/; # It's not a sin..
Branch: 1 branch
BranchTrueFalseTotal
if $err =~ /Can't locate/ 3 0 3
67 0 printf STDERR "WARNING errors loading customisations for $class.. %s\n", $err;
68 }
69  
70 # rinse and repeat..
71 1 $self->schema->source_registrations({});
72 1 for my $table (@tables) {
73 3 my $moniker = $self->monikers->{$table->sql_name};
74 3 my $class = $self->classes->{$table->sql_name};
75 3 $self->schema->register_class($moniker=>$class);
76 }
77  
78 # all table meta-data including relationships are now has fully 'registered'.
79 1 return \@tables;
80 }
81  
82 # Override existing Loader::Base actions to actually run code rather than generate it..
83  
84 16 ▶sub _dbic_stmt {
Subroutine _dbic_stmt: called CC=2 SCAR=7.1
85 16 my ($self, $class, $method, @args) = @_;
86 16 ▶ printf STDERR "DBIC_STMT %s ( %s )\n", "$class->$method(@args);", Dumper(\@args) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 16 16
87 16 $class->$method(@args);
88 }
89  
90 6 ▶sub _inject {
Subroutine _inject: called CC=2 SCAR=6.9
91 6 my ($self, $class, @parents) = @_;
92 6 ▶ return unless @parents;
Branch: 1 branch
BranchTrueFalseTotal
unless @parents 3 3 6
93 3 my $isa = "$class\::ISA";
94 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 3 unshift @$isa, @parents;
96 }
97  
98 0 ▶sub _base_class_pod {}
Subroutine _base_class_pod: not called CC=1 SCAR=0.0
99 0 ▶sub _make_pod {}
Subroutine _make_pod: not called CC=1 SCAR=0.0
100 0 ▶sub _make_pod_heading {}
Subroutine _make_pod_heading: not called CC=1 SCAR=0.0
101 0 ▶sub _pod {}
Subroutine _pod: not called CC=1 SCAR=0.0
102 12 ▶sub _pod_class_list {}
Subroutine _pod_class_list: called CC=1 SCAR=0.0
103 0 ▶sub _pod_cut {}
Subroutine _pod_cut: not called CC=1 SCAR=0.0
104 3 ▶sub _use {}
Subroutine _use: called CC=1 SCAR=0.0
105  
106 1 1;
107  
108 __END__
↑ Summary