File Coverage

blib/lib/DBIx/DataModel/Schema/ResultAs/Correlated_update.pm
Criterion Covered Total %
statement 31 31 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 2 50.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             #----------------------------------------------------------------------
2             package DBIx::DataModel::Schema::ResultAs::Correlated_update;
3             #----------------------------------------------------------------------
4 1     1   916 use warnings;
  1         4  
  1         77  
5 1     1   8 use strict;
  1         2  
  1         31  
6 1     1   6 use DBIx::DataModel::Statement;
  1         3  
  1         29  
7              
8 1     1   7 use parent 'DBIx::DataModel::Schema::ResultAs';
  1         2  
  1         9  
9              
10             sub new {
11 1     1 0 4 my ($class, $to_set) = @_;
12 1         6 bless {to_set => $to_set}, $class;
13             }
14              
15             sub get_result {
16 1     1 1 2 my ($self, $statement) = @_;
17              
18 1         6 $statement->_forbid_callbacks(__PACKAGE__);
19 1         5 $statement->sqlize;
20              
21 1         4 my ($sql, @bind) = $statement->sql;
22 1         4 my $schema = $statement->schema;
23 1         9 my $to_set = $self->{to_set};
24 1         5 $sql = "UPDATE ($sql) SET " . join ", ", map {"$_=$to_set->{$_}"} keys %$to_set;
  1         7  
25 1     1   239 $schema->_debug(do {no warnings 'uninitialized'; $sql . " / " . CORE::join(", ", @bind);});
  1         3  
  1         201  
  1         3  
  1         7  
26              
27 1         4 my $prepare_method = $schema->dbi_prepare_method;
28 1         5 my $sth = $schema->dbh->$prepare_method($sql);
29              
30 1         328 $statement->sql_abstract->bind_params($sth, @bind);
31 1         22 return $sth->execute(); # will return the number of updated records
32             }
33              
34             1;
35              
36             __END__