Branch Coverage

blib/lib/Perinci/Tx/Manager.pm
Criterion Covered Total %
branch 241 380 63.4


line true false branch
38 0 666 if $res
41 0 666 if $res
78 0 33 unless &blessed($opts{'pa'})
80 0 33 unless $opts{'pa'}->isa('Perinci::Access::Schemeless')
83 33 0 if ($opts{'data_dir'}) { }
84 4 29 unless (-d $opts{'data_dir'})
85 0 4 unless mkdir $opts{'data_dir'}
89 0 0 unless (-d $_)
90 0 0 unless mkdir $_
96 0 33 unless $res->[0] == 200
104 124 201 unless ($self->{'_lock'})
109 0 325 if $@
127 4 29 unless (-d "$self->{'data_dir'}/.trash")
128 0 4 unless mkdir "$self->{'data_dir'}/.trash"
131 4 29 unless (-d "$self->{'data_dir'}/.tmp")
132 0 4 unless mkdir "$self->{'data_dir'}/.tmp"
138 0 33 unless -d $data_dir
141 0 33 unless my $dbh = 'DBI'->connect("dbi:SQLite:dbname=$self->{'_db_file'}", undef, undef, {'RaiseError', 0})
152 0 33 unless $dbh->do("CREATE TABLE IF NOT EXISTS tx (\n ser_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n str_id VARCHAR(200) NOT NULL,\n owner_id VARCHAR(64) NOT NULL,\n summary TEXT,\n status CHAR(1) NOT NULL, -- i, a, C, U, R, u, v, d, e, X [uppercase=final]\n ctime REAL NOT NULL,\n commit_time REAL,\n last_action_id INTEGER,\n UNIQUE (str_id)\n)\n")
176 0 33 unless $dbh->do("CREATE TABLE IF NOT EXISTS do_action (\n tx_ser_id INTEGER NOT NULL, -- refers tx(ser_id)\n id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n sp TEXT, -- for named savepoint\n ctime REAL NOT NULL,\n f TEXT NOT NULL,\n args TEXT NOT NULL,\n UNIQUE(sp)\n)\n")
188 0 33 unless $dbh->do("CREATE TABLE IF NOT EXISTS undo_action (\n tx_ser_id INTEGER NOT NULL, -- refers tx(ser_id)\n action_id INTEGER NOT NULL, -- refers do_action(id)\n id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n ctime REAL NOT NULL,\n f TEXT NOT NULL,\n args TEXT NOT NULL\n)\n")
199 0 33 unless $dbh->do("CREATE TABLE IF NOT EXISTS _meta (\n name TEXT PRIMARY KEY NOT NULL,\n value TEXT\n)\n")
205 0 33 unless $dbh->do("-- v is incremented everytime schema changes\nINSERT OR IGNORE INTO _meta VALUES ('v', '5')\n")
215 0 33 if ($v <= 3) { }
0 33 elsif ($v == 4) { }
262 0 0 if ($e)
278 0 0 unless $tx
280 0 0 unless (-d $d)
281 0 0 unless mkdir $d
289 0 0 unless $tx
291 0 0 unless (-d $d)
292 0 0 unless mkdir $d
300 0 666 unless my($module, $leaf) = $func =~ /(.+)::(.+)/
305 0 666 if ($req_err) { }
0 666 elsif (not package_exists($module)) { }
306 0 0 if (not package_exists($module)) { }
0 0 elsif (not $req_err =~ /Can't locate/) { }
333 126 59 if $self->{'_in_sqltx'}
341 78 106 unless $self->{'_in_sqltx'}
344 106 0 $res ? :
350 2 232 if $self->{'_in_sqltx'}
353 232 0 $res ? :
360 1 665 unless $ff->{'tx'}
361 0 665 unless ($ff->{'tx'}{'v'} // 1) == $proto_v
365 0 665 unless $ff->{'idempotent'}
377 0 466 unless ref $actions eq 'ARRAY'
383 0 667 unless ref $a eq 'ARRAY'
385 372 295 if $opts->{'qualify'} and not $a->[0] =~ /::/
386 0 667 unless $a->[0] =~ /\A\w+(::\w+)+\z/
389 241 426 if ($a->[2]) { }
426 0 elsif ($a->[1]) { }
395 1 666 if $@
397 0 666 unless $res->[0] == 200
401 1 665 unless $res->[0] == 200
418 132 155 if ($whicha eq 'action') { }
52 103 elsif ($whicha eq 'rollback') { }
66 37 elsif ($whicha eq 'undo') { }
37 0 elsif ($whicha eq 'redo') { }
423 6 20 $os eq 'd' ? :
6 26 $os eq 'u' ? :
20 32 $os eq 'i' ? :
424 8 36 $os eq 'd' || $ns eq 'e' ? :
8 44 $os eq 'u' || $ns eq 'v' ? :
433 171 116 if ($which0 eq 'before')
434 85 86 if ($ns ne $os)
439 0 85 unless $dbh->do("UPDATE tx SET status='${ns}', last_action_id=NULL " . 'WHERE ser_id=?', {}, $tx->{'ser_id'})
444 0 85 unless @r
446 0 85 unless $r[0] eq $ns
455 116 171 if ($which0 eq 'after')
456 55 61 if ($whicha eq 'action')
460 0 55 unless $dbh->do('UPDATE tx SET last_action_id=NULL WHERE ser_id=?', {}, $tx->{'ser_id'})
464 61 55 if ($os ne $fs)
470 0 61 unless $dbh->do("UPDATE tx SET status='${fs}',last_action_id=NULL " . 'WHERE ser_id=?', {}, $tx->{'ser_id'})
495 0 94 if $which eq 'action'
500 30 64 $which eq 'redo' || $which eq 'rollback' && $tx->{'status'} eq 'v' ? :
508 4 90 $lai ? :
517 0 0 if $which eq 'rollback'
524 0 0 $which eq 'redo' || $which eq 'rollback' && $tx->{'status'} eq 'v' || $which eq 'action' && !$self->{'_in_undo'} ? :
535 506 0 unless ref $s eq 'HASH'
549 42 233 if $which eq 'rollback'
550 15 260 if $self->{'_in_recovery'}
551 10 265 if $opts->{'confirm'}
553 0 275 if ($dd->{'tmp_dir'})
555 0 0 unless $res->[0] == 200
558 0 275 if ($dd->{'trash_dir'})
560 0 0 unless $res->[0] == 200
571 3 272 unless $res->[0] == 200 or $res->[0] == 304
573 257 0 if $res->[0] == 200 and $res->[1]
579 272 0 unless $_hooks{$_}
586 0 272 unless $res->[0] == 200
588 23 249 if ($do_actions)
590 0 23 unless $res->[0] == 200
595 115 0 if ($which eq 'action' and not $self->{'_in_undo'} and not $self->{'_in_redo'})
599 0 115 unless $dbh->do("INSERT INTO $t (tx_ser_id,ctime,f,args) " . 'VALUES (?,?,?,?)', {}, $tx->{'ser_id'}, &Perinci::Tx::Manager::time(), $action->[0], $action->[2])
604 0 115 unless $dbh->do('UPDATE tx SET last_action_id=? WHERE ser_id=?', {}, $action_id, $tx->{'ser_id'})
611 207 65 unless ($which eq 'rollback' or $do_actions)
618 68 124 if ($self->{'_in_undo'}) { }
622 0 68 unless $dbh->do('INSERT INTO do_action (tx_ser_id,ctime,f,args) VALUES (?,?,?,?)', {}, $tx->{'ser_id'}, &Perinci::Tx::Manager::time(), $ua->[0], $ua->[2])
629 0 124 unless $dbh->do('INSERT INTO undo_action(tx_ser_id,action_id,ctime,f,args)VALUES (?,?,?,?,?)', {}, $tx->{'ser_id'}, $action->[3], &Perinci::Tx::Manager::time(), $ua->[0], $ua->[2])
639 23 249 if ($do_actions and @$do_actions) { }
234 15 elsif ($self->{'_res'}[0] == 200) { }
642 23 0 unless $_hooks{$_}
648 7 16 unless $res->[0] == 200
651 16 0 unless $_hooks{$_}
660 0 234 unless $res->[0] == 200 or $res->[0] == 304
666 139 126 unless $_hooks{$_}
674 124 98 unless ($which eq 'action')
693 77 94 if $which eq 'action'
698 92 79 $self->{'_action_nest_level'} ? :
701 0 171 unless $which =~ /\A(rollback|undo|redo|action)\z/
706 0 171 if $self->{'_in_rollback'} and $which eq 'rollback'
707 32 139 if $which eq 'rollback'
709 38 133 if $which eq 'undo'
710 24 147 if $which eq 'redo'
713 0 171 unless $tx
726 0 171 unless $res->[0] == 200
735 94 77 unless $actions
741 2 169 unless $res->[0] == 200
749 10 222 unless $res->[0] == 200
753 0 116 unless $res->[0] == 200
759 55 116 if ($eval_err or $eval_res->[0] != 200)
760 12 43 if ($which eq 'rollback') { }
16 27 elsif (not $opts->{'rollback'} or ($self->{'_action_nest_level'} // 0) > 1) { }
765 12 0 $eval_err ? :
770 16 0 $eval_err ? :
775 12 15 if ($rbres->[0] != 200) { }
777 9 3 $eval_err ? :
782 6 9 $eval_err ? :
790 0 116 if (log_is_trace())
793 0 0 if $undo_actions
806 0 58 unless $res->[0] == 200
813 0 116 unless -d $dir
820 0 0 if $tx_id ~~ \@tx_ids
847 0 33 unless $res->[0] == 200
859 0 33 unless $sth->execute
870 0 33 unless $sth->execute
881 0 33 unless $sth->execute
943 0 234 unless my $margs = $wargs{'args'}
949 0 234 unless $res->[0] == 200
958 0 234 unless defined $tx_id and length $tx_id
960 0 234 unless length $tx_id <= 200
965 58 176 if ($wargs{'cleanup'})
967 0 58 unless $res->[0] == 200
974 0 234 unless $self->_begin_dbh
980 0 234 if ($wargs{'hook_check_args'})
982 0 0 unless ($res->[0] == 200)
986 176 58 if ($wargs{'tx_status'})
987 12 164 unless ($cur_tx)
993 164 0 if (ref $wargs{'tx_status'} eq 'ARRAY') { }
998 2 162 unless ($ok)
1004 220 0 if ($wargs{'code'})
1007 36 184 if ($res->[0] >= 400)
1009 0 36 if $wargs{'rollback'} // ($res->[3]{'rollback'} // 1)
1015 0 184 unless $res2->[0] == 200
1017 0 184 if ($wargs{'hook_after_commit'})
1019 0 0 unless $res2->[0] == 200
1038 0 141 unless my $margs = $wargs{'args'}
1043 0 141 if ($wargs{'lock_db'})
1045 0 0 unless $res->[0] == 200
1050 0 141 if ($wargs{'lock_db'})
1066 2 56 if $r
1075 0 56 unless $dbh->do('INSERT INTO tx (str_id, owner_id, summary, status, ctime) VALUES (?,?,?,?,?)', {}, $args{'tx_id'}, $args{'client_token'} // '', $args{'summary'}, 'i', $self->{'_now'})
1080 0 56 unless $self->{'_cur_tx'} = $dbh->selectrow_hashref('SELECT * FROM tx WHERE str_id=?', {}, $args{'tx_id'})
1100 0 55 unless @$actions
1111 0 54 if ($cur_tx->{'status'} ne 'i' and not $self->{'_in_rollback'})
1117 15 39 if ($res->[0] != 200 and $res->[0] != 304) { }
1118 3 12 if ($self->{'_res'} and not $self->{'_res'}[0] =~ /200|304/) { }
1145 0 33 if ($tx->{'status'} eq 'a')
1147 0 0 unless $res->[0] == 200
1154 0 33 unless $dbh->do('UPDATE tx SET status=?, commit_time=? WHERE ser_id=?', {}, 'C', $self->{'_now'}, $tx->{'ser_id'})
1167 12 20 unless $res->[0] == 200
1179 10 28 unless $res->[0] == 200
1190 11 13 unless $res->[0] == 200
1227 74 8 if ($args{'tx_id'})
1231 6 76 if ($args{'tx_status'})
1241 74 7 if ($args{'detail'}) { }
1262 0 34 unless ($args{'tx_id'})
1267 0 0 unless @row
1278 10 24 if ($res->[0] != 200 and $res->[0] != 304) { }
1279 0 10 if ($self->{'_res'} and not $self->{'_res'}[0] =~ /200|304/) { }
1298 0 19 unless ($args{'tx_id'})
1303 0 0 unless @row
1314 11 8 if ($res->[0] != 200 and $res->[0] != 304) { }
1315 0 11 if ($self->{'_res'} and not $self->{'_res'}[0] =~ /200|304/) { }
1332 28 59 $which eq 'one' ? :
1340 17 59 if ($which eq 'one') { }
1345 58 1 if ($args{'status'})
1357 37 39 if (@txs)
1359 0 37 unless $dbh->do("DELETE FROM tx WHERE ser_id IN ($txs)")
1366 28 59 $which eq 'one' ? :