line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::DoubleLinked::Iterator; |
2
|
|
|
|
|
|
|
$List::DoubleLinked::Iterator::VERSION = '0.005'; |
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
7
|
1
|
|
|
1
|
|
4
|
use Scalar::Util 'weaken'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
3
|
use namespace::clean 0.20; |
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload |
11
|
|
|
|
|
|
|
'==' => sub { |
12
|
1
|
|
|
1
|
|
79
|
my ($left, $right, $switch) = @_; |
13
|
1
|
|
|
|
|
9
|
return $left->[0] == $right->[0]; |
14
|
|
|
|
|
|
|
}, |
15
|
|
|
|
|
|
|
'!=' => sub { |
16
|
7
|
|
|
7
|
|
8
|
my ($left, $right, $switch) = @_; |
17
|
7
|
|
|
|
|
9
|
return $left->[0] != $right->[0]; |
18
|
|
|
|
|
|
|
}, |
19
|
1
|
|
|
1
|
|
196
|
fallback => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
18
|
|
|
18
|
0
|
14
|
my ($class, $node) = @_; |
23
|
18
|
|
|
|
|
22
|
my $self = bless [ $node ], $class; |
24
|
18
|
|
|
|
|
102
|
weaken $self->[0]; |
25
|
18
|
|
|
|
|
13
|
Internals::SvREADONLY(@{$self}, 1); |
|
18
|
|
|
|
|
23
|
|
26
|
18
|
|
|
|
|
37
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
9
|
|
|
9
|
1
|
22
|
my $self = shift; |
31
|
9
|
50
|
|
|
|
14
|
return if not defined $self->[0]; |
32
|
9
|
|
|
|
|
19
|
return $self->[0]{item}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub next { |
38
|
8
|
|
|
8
|
1
|
5
|
my $self = shift; |
39
|
8
|
|
|
|
|
6
|
my $node = $self->[0]; |
40
|
8
|
50
|
|
|
|
11
|
croak 'Node no longer exists' if not defined $node; |
41
|
8
|
|
|
|
|
10
|
return __PACKAGE__->new($node->{next}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub previous { |
45
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
46
|
1
|
|
|
|
|
1
|
my $node = $self->[0]; |
47
|
1
|
50
|
|
|
|
3
|
croak 'Node no longer exists' if not defined $node; |
48
|
1
|
|
|
|
|
2
|
return __PACKAGE__->new($node->{prev}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub insert_before { |
52
|
1
|
|
|
1
|
1
|
2
|
my ($self, @items) = @_; |
53
|
1
|
|
|
|
|
1
|
my $node = $self->[0]; |
54
|
1
|
|
|
|
|
2
|
for my $item (reverse @items) { |
55
|
|
|
|
|
|
|
my $new_node = { |
56
|
|
|
|
|
|
|
item => $item, |
57
|
|
|
|
|
|
|
prev => $node->{prev}, |
58
|
2
|
|
|
|
|
4
|
next => $node, |
59
|
|
|
|
|
|
|
}; |
60
|
2
|
|
|
|
|
2
|
$node->{prev}{next} = $new_node; |
61
|
2
|
|
|
|
|
2
|
$node->{prev} = $new_node; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
2
|
$node = $new_node; |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
2
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub insert_after { |
69
|
1
|
|
|
1
|
1
|
2
|
my ($self, @items) = @_; |
70
|
1
|
|
|
|
|
2
|
my $node = $self->[0]; |
71
|
1
|
|
|
|
|
2
|
for my $item (@items) { |
72
|
|
|
|
|
|
|
my $new_node = { |
73
|
|
|
|
|
|
|
item => $item, |
74
|
|
|
|
|
|
|
prev => $node, |
75
|
|
|
|
|
|
|
next => $node->{next}, |
76
|
2
|
|
|
|
|
3
|
}; |
77
|
2
|
|
|
|
|
3
|
$node->{next}{prev} = $new_node; |
78
|
2
|
|
|
|
|
2
|
$node->{next} = $new_node; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
2
|
$node = $new_node; |
81
|
|
|
|
|
|
|
} |
82
|
1
|
|
|
|
|
1
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# ABSTRACT: Double Linked List Iterators |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |