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