Lite/Schema.pm

filter: Statementstmt 93.3% 42 / 45 Branchbran 57.1% 8 / 14 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 76.1% 64 / 84 CC 12 SCAR 17.0
CC
12
Cov
79%
one_to_many
9.0
new
4.7
table
2.0
CRAP 5.5
« Lite.pm ↑ Summary Lite/Schema/Table.pm »
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
BranchTrueFalseTotal
if (my $tables = delete $params{"tables"}) 0 5 5
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
BranchTrueFalseTotal
%params and croak('Unknown options: ' . join(", ", keys %params)) 0 5 5
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)
l!l&&r!l&&!r
4380
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$from and $from =~ /^(.+)\.(.+)$/ or croak("Relationship keys must be defined in table.column format") 2 0 2
Condition33%1/3
$from and $from =~ /^(.+)\.(.+)$/
!ll&&!rl&&r
002
MC/DC0%0/2
$from and $from =~ /^(.+)\.(.+)$/
$from $from =~ /^(.+)\.(.+)$/
Truth table33%1/3
A and B
A= $fromB= $from =~ /^(.+)\.(.+)$/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$to and $to =~ /^(.+)\.(.+)$/ or croak("Relationship keys must be defined in table.column format") 2 0 2
Condition33%1/3
$to and $to =~ /^(.+)\.(.+)$/
!ll&&!rl&&r
002
MC/DC0%0/2
$to and $to =~ /^(.+)\.(.+)$/
$to $to =~ /^(.+)\.(.+)$/
Truth table33%1/3
A and B
A= $toB= $to =~ /^(.+)\.(.+)$/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($accessors) 2 0 2
56 2 ▶ if (ref $accessors eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $accessors eq 'ARRAY') { } 1 1 2
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
BranchTrueFalseTotal
if $to_table_accessor 2 0 2
65 if $to_table_accessor;
66 }
67  
68 7 1;
69  
70 __END__
« Lite.pm ↑ Summary Lite/Schema/Table.pm »