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