line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Transactional.pm,v 1.6 2004/04/08 19:36:28 claes Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Array::Stream::Transactional; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7468
|
use 5.00503; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
638
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
1
|
|
|
1
|
1
|
517
|
my ($class, $tokens) = @_; |
14
|
1
|
|
33
|
|
|
8
|
$class = ref $class || $class; |
15
|
1
|
50
|
|
|
|
6
|
croak "Not an ARRAY reference" unless(UNIVERSAL::isa($tokens, "ARRAY")); |
16
|
1
|
|
|
|
|
18
|
my $self = bless { data => $tokens }, $class; |
17
|
1
|
|
|
|
|
7
|
$self->reset; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
4
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub reset { |
23
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
24
|
2
|
|
|
|
|
9
|
$self->{pos} = 0; |
25
|
2
|
|
|
|
|
5
|
$self->{transactions} = []; |
26
|
2
|
|
|
|
|
8
|
$self->{current} = $self->{data}->[0]; |
27
|
2
|
|
|
|
|
3
|
$self->{previous} = undef; |
28
|
2
|
|
|
|
|
4
|
1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub pos { |
32
|
8
|
|
|
8
|
1
|
42
|
$_[0]->{pos}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub next { |
36
|
300
|
|
|
300
|
1
|
764
|
my $self = shift; |
37
|
300
|
|
|
|
|
580
|
$self->{previous} = $self->{current}; |
38
|
300
|
|
|
|
|
559
|
$self->{current} = $self->{data}->[++$self->{pos}]; |
39
|
300
|
|
|
|
|
742
|
return $self->{current}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub rewind { |
43
|
1
|
|
|
1
|
1
|
90
|
my $self = shift; |
44
|
1
|
|
|
|
|
2
|
$self->{previous} = $self->{current}; |
45
|
1
|
|
|
|
|
4
|
$self->{current} = $self->{data}->[--$self->{pos}]; |
46
|
1
|
|
|
|
|
3
|
return $self->{current}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub following { |
50
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
51
|
1
|
50
|
|
|
|
3
|
return undef if($self->{pos} == @{$self->{data}}); |
|
1
|
|
|
|
|
6
|
|
52
|
1
|
|
|
|
|
5
|
return $self->{data}->[$self->{pos} + 1]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub commit { |
56
|
5
|
|
|
5
|
1
|
14
|
my $self = shift; |
57
|
5
|
|
|
|
|
8
|
push @{$self->{transactions}}, [ $self->{pos}, $self->{current}, $self->{previous} ]; |
|
5
|
|
|
|
|
20
|
|
58
|
5
|
|
|
|
|
12
|
1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub rollback { |
62
|
4
|
|
|
4
|
1
|
13
|
my $self = shift; |
63
|
4
|
50
|
|
|
|
6
|
croak "No more commits to rollback" unless(@{$self->{transactions}}); |
|
4
|
|
|
|
|
79
|
|
64
|
4
|
|
|
|
|
8
|
($self->{pos}, $self->{current}, $self->{previous}) = @{pop @{$self->{transactions}}}; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
21
|
|
65
|
4
|
|
|
|
|
10
|
1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub regret { |
69
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
70
|
1
|
50
|
|
|
|
2
|
croak "No more commits to regret" unless(@{$self->{transactions}}); |
|
1
|
|
|
|
|
5
|
|
71
|
1
|
|
|
|
|
2
|
return @{pop @{$self->{transactions}}}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub current { |
75
|
406
|
|
|
406
|
1
|
513
|
my $self = shift; |
76
|
406
|
|
|
|
|
1145
|
return $self->{current}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub previous { |
80
|
5
|
|
|
5
|
1
|
18
|
my $self = shift; |
81
|
5
|
|
|
|
|
23
|
return $self->{previous}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub length { |
85
|
1
|
|
|
1
|
1
|
184
|
my $self = shift; |
86
|
1
|
|
|
|
|
120
|
return scalar @{$self->{data}}; |
|
1
|
|
|
|
|
7
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub has_more { |
90
|
252
|
|
|
252
|
1
|
313
|
my $self = shift; |
91
|
252
|
|
|
|
|
297
|
return $self->{pos} < @{$self->{data}}; |
|
252
|
|
|
|
|
753
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |