Declarative/JRow.pm

filter: Statementstmt 18.3% 11 / 60 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 50.0% 3 / 6 Podpod 100% 2 / 2 totaltotal 13.9% 16 / 115 CC 17 SCAR 43.4
CC
17
Cov
11%
commit
110.0
__create_where
72.0
delete
2.0
CRAP 76.4
« Declarative/Table.pm ↑ Summary Declarative/Row.pm »
1 package DBIx::ORM::Declarative::JRow;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 @ISA = qw(DBIx::ORM::Declarative::Row);
8  
9 sub delete
10 0 ▶{
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
11 0 carp "You must delete each component of a join individually";
12 0 return;
13 }
14  
15 # Create a collection of where clause to find this particular join object
16 sub __create_where
17 0 ▶{
Subroutine __create_where: not called CC=8 SCAR=42.8
18 0 my ($self) = @_;
19 0 ▶ carp "not a class method" and return unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
Condition0%0/5
ref $self || carp('not a class method') && (return)
l!l&&r!l&&!r
000
carp("not a class method") and return
!ll
00
MC/DC0%0/2
ref $self || carp('not a class method') && (return)
ref $self carp("not a class method")
Truth table0%0/3
A || B
A= ref $selfB= carp("not a class method")
ABresult
1X1
011
000
20  
21 # Assemble the information, if we haven't already
22 0 ▶ if(not exists $self->{__whereinfo})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__whereinfo"}) 0 0 0
23 {
24 # We'll work on these tables...
25 0 for my $table ($self->_primary, map { $_->{table} } $self->_join_info)
26 {
27 0 my $tab_obj = $self->table($table);
28
29 # Get a list of keys to use
30 0 my ($un) = $tab_obj->_unique_keys;
31 0 ▶ $un ||= [ map { $_->{name} } $tab_obj->_columns ];
Condition0%0/2
$un ||= [map({$_->{"name"};} $tab_obj->_columns)]
l!l
00
MC/DC0%0/1
$un ||= [map({$_->{"name"};} $tab_obj->_columns)]
$un
Truth table0%0/2
A
A= $un
Aresult
11
00
32 0 my %name2sql_map = $tab_obj->_column_map;
33  
34 # Get the data and keys
35 0 my (@wclause, @binds);
36 0 for my $key (@$un)
37 {
38 0 my $sql_name = $name2sql_map{$key};
39 0 my $value = $self->{__data}{"$table.$sql_name"};
40  
41 # Create the subclause
42 0 ▶ if(defined $value)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
43 {
44 0 push @wclause, "$sql_name=?";
45 0 push @binds, $value;
46 }
47 else
48 {
49 0 push @wclause, "$sql_name IS NULL";
50 }
51 }
52  
53 # Paste it all together
54 0 @{$self->{__whereinfo}{$table}} =
55 # The WHERE clause the data
56 (join(' AND ', @wclause), @binds);
57 }
58 }
59  
60 0 return %{$self->{__whereinfo}};
61 }
62  
63 sub commit
64 0 ▶{
Subroutine commit: not called CC=10 SCAR=47.0
Pod documented
65 0 my ($self) = @_;
66 0 ▶ carp "commit: not a class method" and return unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
Condition0%0/5
ref $self || carp('commit: not a class method') && (return)
l!l&&r!l&&!r
000
carp("commit: not a class method") and return
!ll
00
MC/DC0%0/2
ref $self || carp('commit: not a class method') && (return)
ref $self carp("commit: not a class method")
Truth table0%0/3
A || B
A= ref $selfB= carp("commit: not a class method")
ABresult
1X1
011
000
67 0 ▶ return $self unless $self->{__dirty};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__dirty"} 0 0 0
68 0 my $handle = $self->handle;
69 0 ▶ carp "Can't commit without a handle" and return unless $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless $handle 0 0 0
Condition0%0/5
$handle || carp(q[Can't commit without a handle]) && (return)
l!l&&r!l&&!r
000
carp("Can't commit without a handle") and return
!ll
00
MC/DC0%0/2
$handle || carp(q[Can't commit without a handle]) && (return)
$handle carp("Can't commit without a handle")
Truth table0%0/3
A || B
A= $handleB= carp("Can't commit without a handle")
ABresult
1X1
011
000
70  
71 # Give it the business...
72 0 my %whereinfo = $self->__create_where;
73 0 for my $table (keys %whereinfo)
74 {
75 # Gather our data
76 0 my $tab_obj = $self->table($table);
77 0 my @cols= map { $_->{sql_name} } $tab_obj->_columns;
78  
79 # Silly as it may be, a table with no columns is still "legal"
80 0 ▶ carp "encountered a table with no columns" and next unless @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @cols 0 0 0
Condition0%0/5
@cols || carp('encountered a table with no columns') && (next)
l!l&&r!l&&!r
000
carp("encountered a table with no columns") and next
!ll
00
MC/DC0%0/2
@cols || carp('encountered a table with no columns') && (next)
@cols carp("encountered a table with no columns")
Truth table0%0/3
A || B
A= @colsB= carp("encountered a table with no columns")
ABresult
1X1
011
000
81  
82 0 my ($wclause, @binds) = @{$whereinfo{$table}};
83 0 unshift @binds, @{$self->{__data}}{map { "$table.$_" } @cols};
84  
85 # The SQL statement
86 0 my $table_name = $tab_obj->_sql_name;
87 my $sql = "UPDATE $table_name SET "
88 0 . join(',', map { "$_=?" } @cols) . " WHERE $wclause";
89  
90 0 ▶ if(not $handle->do($sql, undef, @binds))
Branch: 1 branch
BranchTrueFalseTotal
unless ($handle->do($sql, undef, @binds)) 0 0 0
91 {
92 0 carp "Database error: ", $handle->errstr;
93 0 $self->__do_rollback;
94 0 return;
95 }
96 }
97  
98 0 delete $self->{__dirty};
99 0 return $self;
100 }
101  
102 1 1;
103 __END__
« Declarative/Table.pm ↑ Summary Declarative/Row.pm »