• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DrHyde / perl-modules-Data-Transactional / 10204671646

01 Aug 2024 07:37PM UTC coverage: 90.0%. Remained the same
10204671646

Pull #20

github

web-flow
Bump cross-platform-actions/action from 0.24.0 to 0.25.0

Bumps [cross-platform-actions/action](https://github.com/cross-platform-actions/action) from 0.24.0 to 0.25.0.
- [Release notes](https://github.com/cross-platform-actions/action/releases)
- [Changelog](https://github.com/cross-platform-actions/action/blob/master/changelog.md)
- [Commits](https://github.com/cross-platform-actions/action/compare/v0.24.0...v0.25.0)

---
updated-dependencies:
- dependency-name: cross-platform-actions/action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #20: Bump cross-platform-actions/action from 0.24.0 to 0.25.0

126 of 140 relevant lines covered (90.0%)

12.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/lib/Tie/Hash/Transactional.pm
1
package Tie::Hash::Transactional;
2

3
use strict;
2✔
4

5
my $VERSION='1.1';
6

7
sub TIEHASH {
8
        my $class = shift;
3✔
9
        my %params = @_;
3✔
10
        my $self = {
3✔
11
                STACK                => [],
12
                CURRENT_STATE        => {},
13
        };
14
        
15
        warn(__PACKAGE__." is deprecated\n") unless($params{nowarn});
3✔
16

17
        return bless $self, $class;
3✔
18
}
19

20
sub checkpoint {
21
        my $self = shift;
2✔
22
        # make a new copy of CURRENT_STATE before putting on stack,
23
        # otherwise CURRENT_STATE and top-of-STACK will reference the
24
        # same data structure, which would be a Bad Thing
25
        my %hash_for_stack = %{$self->{CURRENT_STATE}};
2✔
26
        push @{$self->{STACK}}, \%hash_for_stack;
2✔
27
}
28

29
sub commit {
30
        my $self = shift;
×
31
        $self->{STACK}=[];                     # clear all checkpoints
×
32
}
33

34
sub rollback {
35
        my $self = shift;
3✔
36
        die("Attempt to rollback too far") unless(scalar @{$self->{STACK}});
3✔
37
        # no copying required, just update a pointer
38
        $self->{CURRENT_STATE}=pop @{$self->{STACK}};
2✔
39
}
40

41
sub CLEAR {
42
        my $self=shift;
2✔
43
        $self->{CURRENT_STATE}={};
2✔
44
}
45

46
sub STORE {
47
        my($self, $key, $value)=@_;
8✔
48
        $self->{CURRENT_STATE}->{$key}=$value;
8✔
49
}
50

51
sub FETCH {
52
        my($self, $key) = @_;
12✔
53
        $self->{CURRENT_STATE}->{$key};
12✔
54
}
55

56
sub FIRSTKEY {
57
        my $self = shift;
4✔
58
        scalar keys %{$self->{CURRENT_STATE}};
4✔
59
        scalar each %{$self->{CURRENT_STATE}};
4✔
60
}
61

62
sub NEXTKEY { my $self = shift; scalar each %{$self->{CURRENT_STATE}}; }
12✔
63
sub DELETE { my($self, $key) = @_; delete $self->{CURRENT_STATE}->{$key}; }
1✔
64
sub EXISTS { my($self, $key) = @_; exists($self->{CURRENT_STATE}->{$key}); }
3✔
65

66
1;
67
__END__
68

69
=head1 NAME
70

71
Tie::Hash::Transactional - A hash with checkpoints and rollbacks
72

73
=head1 STATUS
74

75
This module is deprecated.  Please use Data::Transactional instead.
76

77
=head1 SYNOPSIS
78

79
  use Tie::Hash::Transactional
80

81
  tie my %transact_hash, 'Tie::Hash::Transactional';
82
  %transact_hash = (
83
    good => 'perl',
84
    bad  => 'java',
85
    ugly => 'tcl'
86
  );
87

88
  tied(%transact_hash)->checkpoint();
89
  $transact_hash{indifferent} = 'C';
90

91
  # hmmm ... must avoid controversial sample code, so ...
92
  tied(%transact_hash)->rollback();
93

94
=head1 DESCRIPTION
95

96
This module implements a hash with RDBMS-like transactions.  You can
97
checkpoint the hash (that is, you can save its current state), and you
98
can rollback the hash (restore it to the previous saved state).  You
99
can checkpoint and rollback multiple times, as checkpointed states are
100
saved on a stack.
101

102
When tieing, a single named parameter is accepted.  If you pass a true
103
value for the C<nowarn> parameter, the module will not emit warnings
104
about it being deprecated.
105

106
=head1 METHODS
107

108
The following methods are available.  Call them thus:
109

110
C<tied(%my_hash)-E<gt>methodname();>
111

112
=over 4
113

114
=item checkpoint
115

116
Saves the current state of the hash onto the stack, so that it can be
117
retrieved later.
118

119
=item commit
120

121
Discards all saved states from the stack.  Why bother?  Well, if your
122
transactional hash contains a lot of data, then if you have a load of
123
checkpoints on the stack, then it's going to consume a vast amount of
124
memory - each state on the stack is just a copy of the hash as it was
125
when you checkpointed.  Once you are sure that your hash contains the
126
data you want it to contain, and you no longer need any of the previous
127
states, you can free a lot of memory of commiting.
128

129
=item rollback
130

131
Retrieve the last saved state from the stack.  Any changes you have
132
made since the last checkpoint are discarded.  It is a fatal error
133
to rollback with nothing on the stack.
134

135
=back
136

137
=head1 BUGS
138

139
No support for anything other than scalars in the hash.  You can store and
140
retrieve
141
references to data structures, but changes to their contents will not be
142
transactional.
143

144
=head1 AUTHOR
145

146
David Cantrell <david@cantrell.org.uk>
147

148
=head1 COPYRIGHT
149

150
Copyright 2001, 2004 David Cantrell.
151

152
This module is licensed under the same terms as perl itself.
153

154
=head1 SEE ALSO
155

156
Tie::Hash(3)
157

158
=cut
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc