KiokuDB/LiveObjects/TXNScope.pm

filter: Statementstmt 100% 29 / 29 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 93.0% 40 / 43 CC 4 SCAR 5.9
CC
4
Cov
97%
DEMOLISH
3.0
push
2.0
BEGIN
1.0
CRAP 1.8
« KiokuDB/Test/Fixture/Refresh.pm ↑ Summary KiokuDB/Role/Verbosity.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::LiveObjects::TXNScope;
4 22 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 22 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has entries => (
11 isa => "ArrayRef",
12 is => "ro",
13 1094 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 22 );
15  
16 22 has live_objects => (
17 isa => "KiokuDB::LiveObjects",
18 is => "ro",
19 required => 1,
20 );
21  
22 22 has parent => (
23 isa => __PACKAGE__,
24 is => "ro",
25 );
26  
27 sub push {
28 3595 ▶ my ( $self, @entries ) = @_;
Subroutine push: called CC=2 SCAR=6.9
Pod undocumented
29  
30 3595 my $e = $self->entries;
31  
32 3595 foreach my $entry ( @entries ) {
33 3595 push @$e, $entry;
34 3595 weaken($e->[-1]);
35 }
36 }
37  
38 sub rollback {
39 228 ▶ my $self = shift;
Subroutine rollback: called CC=1 SCAR=0.0
Pod documented
40 228 $self->live_objects->rollback_entries(grep { defined } splice @{ $self->entries });
41 }
42  
43 sub DEMOLISH {
44 1094 ▶ my $self = shift;
Subroutine DEMOLISH: called CC=3 SCAR=11.0
Pod undocumented
45  
46 1094 ▶ if ( my $l = $self->live_objects ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $self->live_objects) 1094 0 1094
47 1094 ▶ if ( my $parent = $self->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) { } 64 1030 1094
48 64 $l->_set_txn_scope($parent);
49 } else {
50 1030 $l->_clear_txn_scope();
51 }
52 }
53 }
54  
55 22 __PACKAGE__->meta->make_immutable;
56  
57 22 __PACKAGE__
58  
59 __END__
60  
61 =pod
62  
63 =head1 NAME
64  
65 KiokuDB::LiveObjects::TXNScope - Transaction scope.
66  
67 =head1 SYNOPSIS
68  
69 $txn_scope = $live_objects->new_txn;
70  
71 $txn_scope->update_entries(@updated);
72  
73 $txn_scope->rollback;
74  
75 =head1 DESCRIPTION
76  
77 This is an auxillary class used by transaction scoping to roll back entrries
78 updated during a transaction when it is aborted.
79  
80 This is used internally in L<KiokuDB/txn_do> and should not need to be used
81 directly.
82  
83 =head1 ATTRIBUTES
84  
85 =over 4
86  
87 =item entries
88  
89 An ordered log of updated entries.
90  
91 =back
92  
93 =head1 METHODS
94  
95 =over 4
96  
97 =item update_entries
98  
99 Called by L<KiokuDB::LiveObjects/update_entries>. Adds entries to C<entries>.
100  
101 =item rollback
102  
103 Calls C<KiokuDB::LiveObjects/rollback_entries> with all the recorded entries.
104  
105 =back
106  
107 =cut
108  
109  
« KiokuDB/Test/Fixture/Refresh.pm ↑ Summary KiokuDB/Role/Verbosity.pm »