| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------# |
|
2
|
|
|
|
|
|
|
# Tie::Scalar::Transactional # |
|
3
|
|
|
|
|
|
|
# # |
|
4
|
|
|
|
|
|
|
# Copyright (c) 2002-03 Arun Kumar U . # |
|
5
|
|
|
|
|
|
|
# All rights reserved. # |
|
6
|
|
|
|
|
|
|
# # |
|
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or # |
|
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. # |
|
9
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------# |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Tie::Scalar::Transactional; |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
8523
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
14
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
70
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
8
|
use Exporter; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
60
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @EXPORT_OK @ISA %EXPORT_TAGS); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
816
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@EXPORT_OK = qw( commit rollback ); |
|
22
|
|
|
|
|
|
|
%EXPORT_TAGS = ( commit => \@EXPORT_OK, rollback => \@EXPORT_OK ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
1
|
|
|
1
|
1
|
114
|
my $class = $_[0]; |
|
29
|
1
|
|
|
|
|
4
|
my $var = $_[1]; |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
8
|
if (!defined($var)) { croak('Usage: ' . __PACKAGE__ . '->new($var)'); } |
|
|
0
|
50
|
|
|
|
0
|
|
|
32
|
|
|
|
|
|
|
elsif (ref($var)) { |
|
33
|
0
|
|
|
|
|
0
|
my $message = "References are not allowed\n"; |
|
34
|
0
|
|
|
|
|
0
|
croak("$message\nUsage: " . __PACKAGE__ . '->new($var)'); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
6
|
my $self = tie $_[1], $class, $_[1]; |
|
38
|
1
|
|
|
|
|
3
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub TIESCALAR |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
2
|
|
|
2
|
|
5
|
my ($proto, $var) = @_; |
|
44
|
2
|
|
|
|
|
2
|
my ($self, $class); |
|
45
|
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
5
|
$self = {}; |
|
47
|
2
|
|
33
|
|
|
11
|
$class = ref($proto) || $proto; |
|
48
|
2
|
|
|
|
|
5
|
bless $self, $class; |
|
49
|
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
8
|
$self->_initialize($var); |
|
51
|
2
|
|
|
|
|
7
|
return $self; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _initialize |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
2
|
|
|
2
|
|
4
|
my ($self, $value) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
11
|
$self->{'_committedValue'} = $value; |
|
59
|
2
|
|
|
|
|
5
|
$self->{'_currentValue'} = $value; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub FETCH |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
15
|
|
|
15
|
|
40
|
my ($self) = @_; |
|
65
|
15
|
|
|
|
|
65
|
return $self->{'_currentValue'}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub STORE |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
5
|
|
|
5
|
|
10
|
my ($self, $value) = @_; |
|
71
|
5
|
|
|
|
|
16
|
$self->{'_currentValue'} = $value; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub DESTROY |
|
75
|
0
|
|
|
0
|
|
0
|
{ |
|
76
|
|
|
|
|
|
|
## Nothing to be done (atleast in this version !!) |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub commit |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
2
|
|
|
2
|
1
|
6
|
my $self; |
|
82
|
|
|
|
|
|
|
|
|
83
|
2
|
50
|
|
|
|
7
|
if (@_ == 1) { |
|
|
|
0
|
|
|
|
|
|
|
84
|
2
|
50
|
|
|
|
8
|
if (UNIVERSAL::isa($_[0], __PACKAGE__)) { $self = $_[0]; } |
|
|
2
|
|
|
|
|
4
|
|
|
85
|
|
|
|
|
|
|
else { |
|
86
|
0
|
0
|
|
|
|
0
|
$self = tied($_[0]) if (!ref($_[0])); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
0
|
|
|
|
|
0
|
elsif (@_ == 2) { $self = tied($_[1]); } |
|
90
|
|
|
|
|
|
|
else { |
|
91
|
0
|
|
|
|
|
0
|
my $package = __PACKAGE__; |
|
92
|
0
|
|
|
|
|
0
|
croak(<<"USAGE"); |
|
93
|
|
|
|
|
|
|
Usage: $package->commit(\$var); |
|
94
|
|
|
|
|
|
|
tied(\$var)->commit(); |
|
95
|
|
|
|
|
|
|
commit(\$a); # (if explicitely imported) |
|
96
|
|
|
|
|
|
|
USAGE |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
6
|
$self->{'_committedValue'} = $self->{'_currentValue'}; |
|
100
|
2
|
|
|
|
|
4
|
return 1; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub rollback |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
5
|
|
|
5
|
1
|
9
|
my $self; |
|
106
|
|
|
|
|
|
|
|
|
107
|
5
|
100
|
|
|
|
16
|
if (@_ == 1) { |
|
|
|
50
|
|
|
|
|
|
|
108
|
4
|
100
|
|
|
|
15
|
if (UNIVERSAL::isa($_[0], __PACKAGE__)) { $self = $_[0]; } |
|
|
3
|
|
|
|
|
19
|
|
|
109
|
|
|
|
|
|
|
else { |
|
110
|
1
|
50
|
|
|
|
4
|
$self = tied($_[0]) if (!ref($_[0])); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
1
|
|
|
|
|
3
|
elsif (@_ == 2) { $self = tied($_[1]); } |
|
114
|
|
|
|
|
|
|
else { |
|
115
|
0
|
|
|
|
|
0
|
my $package = __PACKAGE__; |
|
116
|
0
|
|
|
|
|
0
|
croak(<<"USAGE"); |
|
117
|
|
|
|
|
|
|
Usage: $package->rollback(\$var); |
|
118
|
|
|
|
|
|
|
tied(\$var)->rollback(); |
|
119
|
|
|
|
|
|
|
rollback(\$a); # (if explicitely imported) |
|
120
|
|
|
|
|
|
|
USAGE |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
10
|
$self->{'_currentValue'} = $self->{'_committedValue'}; |
|
124
|
5
|
|
|
|
|
9
|
return 1; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |