| 1 | package DBIx::Lite::Schema; | ||||||||||||||||||||||||||||
| 2 | 7 | $DBIx::Lite::Schema::VERSION = '0.41'; | |||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use DBIx::Lite::Schema::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | $Carp::Internal{$_}++ for __PACKAGE__; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 12 | 5 | my (%params) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | my $self = { | |||||||||||||||||||||||||||
| 15 | tables => {}, | ||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | if (my $tables = delete $params{tables}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | foreach my $table_name (keys %$tables) { | |||||||||||||||||||||||||||
| 20 | 0 | $tables->{$table_name}{name} = $table_name; | |||||||||||||||||||||||||||
| 21 | 0 | $self->{tables}{$table_name} = DBIx::Lite::Schema::Table->new($tables->{$table_name}); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | !%params | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or croak "Unknown options: " . join(', ', keys %params); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 29 | 5 | $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 51 | ▶ | sub table { | ||||||||||||||||||||||||||
|
Subroutine
table: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 51 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 51 | my $table_name = shift; | |||||||||||||||||||||||||||
| 35 | 51 | ▶ | $self->{tables}{$table_name} ||= DBIx::Lite::Schema::Table->new(name => $table_name); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"tables"}{$table_name} ||= "DBIx::Lite::Schema::Table"->new("name", $table_name)
MC/DC0%0/2
$self->{"tables"}{$table_name} ||= "DBIx::Lite::Schema::Table"->new("name", $table_name)
$self->{"tables"}{$table_name}
"DBIx::Lite::Schema::Table"->new("name", $table_name)
Truth table66%2/3
A ||= B
A= $self->{"tables"}{$table_name}B= "DBIx::Lite::Schema::Table"->new("name", $table_name)
| |||||||||||||||||||||||||||||
| 36 | 51 | return $self->{tables}{$table_name}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub one_to_many { | ||||||||||||||||||||||||||
|
Subroutine
one_to_many: called CC=8 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 41 | 2 | my ($from, $to, $accessors) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | $from && $from =~ /^(.+)\.(.+)$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$from and $from =~ /^(.+)\.(.+)$/
MC/DC0%0/2
$from and $from =~ /^(.+)\.(.+)$/
$from
$from =~ /^(.+)\.(.+)$/
Truth table33%1/3
A and B
A= $fromB= $from =~ /^(.+)\.(.+)$/
| |||||||||||||||||||||||||||||
| 44 | or croak "Relationship keys must be defined in table.column format"; | ||||||||||||||||||||||||||||
| 45 | 2 | my $from_table = $self->table($1); | |||||||||||||||||||||||||||
| 46 | 2 | my $from_key = $2; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $to && $to =~ /^(.+)\.(.+)$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$to and $to =~ /^(.+)\.(.+)$/
MC/DC0%0/2
$to and $to =~ /^(.+)\.(.+)$/
$to
$to =~ /^(.+)\.(.+)$/
Truth table33%1/3
A and B
A= $toB= $to =~ /^(.+)\.(.+)$/
| |||||||||||||||||||||||||||||
| 49 | or croak "Relationship keys must be defined in table.column format"; | ||||||||||||||||||||||||||||
| 50 | 2 | my $to_table = $self->table($1); | |||||||||||||||||||||||||||
| 51 | 2 | my $to_key = $2; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | my $from_table_accessor = $to_table->{name}; | |||||||||||||||||||||||||||
| 54 | 2 | my $to_table_accessor; | |||||||||||||||||||||||||||
| 55 | 2 | ▶ | if ($accessors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | if (ref $accessors eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | ($from_table_accessor, $to_table_accessor) = @$accessors; | |||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||
| 59 | 1 | $to_table_accessor = $accessors; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | $from_table->{has_many}{ $from_table_accessor } = [ $to_table->{name}, { $from_key => $to_key } ]; | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | $to_table->{has_one}{ $to_table_accessor } = [ $from_table->{name}, { $to_key => $from_key } ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | if $to_table_accessor; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||