blib/lib/Otogiri/Plugin/BulkInsert.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 28 / 28 CC 2 SCAR 3.4
CC
2
Cov
100%
bulk_insert
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
↑ Summary
1 package Otogiri::Plugin::BulkInsert;
2 2 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = "0.02";
7 2 our @EXPORT = qw(bulk_insert);
8  
9 1 ▶sub bulk_insert {
Subroutine bulk_insert: called CC=2 SCAR=6.9
Pod documented
10 1 my ($self, $table, $key_list, $row_list) = @_;
11  
12 1 my $keys = join(', ', @$key_list);
13 1 my $binds = join(', ', map {'?'} @$key_list);
14  
15 1 my $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $table, $keys, $binds);
16 1 my $sth = $self->dbh->prepare($sql);
17  
18 1 my $txn = $self->txn_scope();
19  
20 1 for my $row (@$row_list) {
21 8 my %rowdata = %$row;
22 8 $sth->execute(@rowdata{@$key_list});
23 }
24  
25 1 $txn->commit();
26  
27 1 $sth->finish;
28 }
29  
30 2 1;
31 __END__
↑ Summary