line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of List-DoubleLinked |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2011 by Leon Timmermans. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
package List::DoubleLinked::Iterator; |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
55
|
$List::DoubleLinked::Iterator::VERSION = '0.003'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
954
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
71
|
|
15
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
133
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
113
|
|
18
|
1
|
|
|
1
|
|
8
|
use Scalar::Util 'weaken'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
19
|
1
|
|
|
1
|
|
5
|
use namespace::clean 0.20; |
|
1
|
|
|
|
|
43
|
|
|
1
|
|
|
|
|
11
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
3
|
|
|
3
|
0
|
7
|
my ($class, $list, $node) = @_; |
23
|
3
|
|
|
|
|
12
|
my $self = bless [ $node, $list ], $class; |
24
|
3
|
|
|
|
|
18
|
weaken $self->[0]; |
25
|
3
|
|
|
|
|
5
|
Internals::SvREADONLY(@{$self}, 1); |
|
3
|
|
|
|
|
10
|
|
26
|
3
|
|
|
|
|
11
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
3
|
|
|
3
|
1
|
17
|
my $self = shift; |
31
|
3
|
50
|
|
|
|
14
|
return if not defined $self->[0]; |
32
|
3
|
|
|
|
|
18
|
return $self->[0]{item}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub next { |
38
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
39
|
1
|
|
|
|
|
2
|
my ($node, $list) = @{$self}; |
|
1
|
|
|
|
|
2
|
|
40
|
1
|
50
|
|
|
|
5
|
croak 'Node no longer exists' if not defined $node; |
41
|
1
|
|
|
|
|
5
|
return __PACKAGE__->new($list, $node->{next}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub previous { |
45
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
46
|
1
|
|
|
|
|
1
|
my ($node, $list) = @{$self}; |
|
1
|
|
|
|
|
4
|
|
47
|
1
|
50
|
|
|
|
4
|
croak 'Node no longer exists' if not defined $node; |
48
|
1
|
|
|
|
|
6
|
return __PACKAGE__->new($list, $node->{prev}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub remove { |
52
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
53
|
1
|
|
|
|
|
2
|
my ($node, $list) = @{$self}; |
|
1
|
|
|
|
|
2
|
|
54
|
1
|
50
|
|
|
|
3
|
croak 'Node already removed' if not defined $node; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
my $item = $node->{item}; |
57
|
1
|
|
|
|
|
3
|
weaken $node; |
58
|
1
|
|
|
|
|
9
|
$list->erase($node); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
6
|
return $item; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub insert_before { |
64
|
1
|
|
|
1
|
1
|
4
|
my ($self, @items) = @_; |
65
|
1
|
|
|
|
|
2
|
my ($node, $list) = @{$self}; |
|
1
|
|
|
|
|
3
|
|
66
|
1
|
|
|
|
|
6
|
return $list->insert_before($self, @items); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub insert_after { |
70
|
1
|
|
|
1
|
1
|
6
|
my ($self, @items) = @_; |
71
|
1
|
|
|
|
|
3
|
my ($node, $list) = @{$self}; |
|
1
|
|
|
|
|
6321
|
|
72
|
1
|
|
|
|
|
36
|
return $list->insert_after($self, @items); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# ABSTRACT: Double Linked List Iterators |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |