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