line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: DLList.pm,v 1.9 2007/07/13 00:00:14 ask Exp $ |
2
|
|
|
|
|
|
|
# $Source: /opt/CVS/Getopt-LL/lib/Getopt/LL/DLList.pm,v $ |
3
|
|
|
|
|
|
|
# $Author: ask $ |
4
|
|
|
|
|
|
|
# $HeadURL$ |
5
|
|
|
|
|
|
|
# $Revision: 1.9 $ |
6
|
|
|
|
|
|
|
# $Date: 2007/07/13 00:00:14 $ |
7
|
|
|
|
|
|
|
package Getopt::LL::DLList; |
8
|
20
|
|
|
20
|
|
49308
|
use strict; |
|
20
|
|
|
|
|
62
|
|
|
20
|
|
|
|
|
1205
|
|
9
|
20
|
|
|
20
|
|
107
|
use warnings; |
|
20
|
|
|
|
|
42
|
|
|
20
|
|
|
|
|
568
|
|
10
|
20
|
|
|
20
|
|
95
|
use Carp qw(croak); |
|
20
|
|
|
|
|
37
|
|
|
20
|
|
|
|
|
1024
|
|
11
|
20
|
|
|
20
|
|
10216
|
use Getopt::LL::DLList::Node; |
|
20
|
|
|
|
|
61
|
|
|
20
|
|
|
|
|
716
|
|
12
|
20
|
|
|
20
|
|
458
|
use Scalar::Util qw(); |
|
20
|
|
|
|
|
43
|
|
|
20
|
|
|
|
|
404
|
|
13
|
|
|
|
|
|
|
#use Class::InsideOut::Policy::Modwheel qw( :std ); |
14
|
20
|
|
|
20
|
|
104
|
use version; our $VERSION = qv('1.0.0'); |
|
20
|
|
|
|
|
33
|
|
|
20
|
|
|
|
|
124
|
|
15
|
20
|
|
|
20
|
|
2203
|
use 5.006_001; |
|
20
|
|
|
|
|
66
|
|
|
20
|
|
|
|
|
1418
|
|
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
20
|
|
141
|
use Class::Dot qw( property isa_Object ); |
|
20
|
|
|
|
|
49
|
|
|
20
|
|
|
|
|
122
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
property head => isa_Object(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
30
|
|
|
30
|
1
|
1040
|
my ($class, $array_ref) = @_; |
24
|
|
|
|
|
|
|
|
25
|
30
|
100
|
100
|
|
|
210
|
if ($array_ref && !_ARRAYLIKE($array_ref)) { |
26
|
1
|
|
|
|
|
229
|
croak 'Argument to Getopt::LL::DLList must be array reference.'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
29
|
|
|
|
|
108
|
my $self = bless { }, $class; |
30
|
|
|
|
|
|
|
|
31
|
29
|
|
|
|
|
108
|
$self->_init($array_ref); |
32
|
|
|
|
|
|
|
|
33
|
29
|
|
|
|
|
223
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init { |
37
|
29
|
|
|
29
|
|
108
|
my ($self, $array_ref) = @_; |
38
|
29
|
100
|
|
|
|
140
|
return if not ref $array_ref; |
39
|
28
|
100
|
|
|
|
42
|
return if not scalar @{$array_ref}; |
|
28
|
|
|
|
|
1693
|
|
40
|
|
|
|
|
|
|
|
41
|
27
|
|
|
|
|
1665
|
my $prev_node = Getopt::LL::DLList::Node->new(); |
42
|
27
|
|
|
|
|
51
|
my $list_head = $prev_node; |
43
|
|
|
|
|
|
|
|
44
|
27
|
|
|
|
|
61
|
for my $array_element (@{$array_ref}) { |
|
27
|
|
|
|
|
83
|
|
45
|
|
|
|
|
|
|
|
46
|
210
|
|
|
|
|
538
|
$prev_node->set_data($array_element); |
47
|
|
|
|
|
|
|
|
48
|
210
|
|
|
|
|
1242
|
my $next_node = Getopt::LL::DLList::Node->new(); |
49
|
210
|
|
|
|
|
531
|
$prev_node->set_next($next_node); |
50
|
210
|
|
|
|
|
1164
|
$next_node->set_prev($prev_node); |
51
|
210
|
|
|
|
|
961
|
$prev_node = $next_node; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# last node is always empty, so delete it. |
56
|
27
|
|
|
|
|
128
|
$prev_node->prev->set_next(undef); |
57
|
27
|
|
|
|
|
334
|
$prev_node->free(); |
58
|
|
|
|
|
|
|
|
59
|
27
|
|
|
|
|
128
|
$self->set_head($list_head); |
60
|
|
|
|
|
|
|
|
61
|
27
|
|
|
|
|
297
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub traverse { |
65
|
30
|
|
|
30
|
1
|
599
|
my ($self, $handler_object, $handler_method) = @_; |
66
|
30
|
|
|
|
|
111
|
my $dll = $self->head; |
67
|
|
|
|
|
|
|
|
68
|
30
|
|
|
|
|
202
|
my $current_node = $dll; |
69
|
30
|
|
|
|
|
60
|
my $nodes_so_far = 0; |
70
|
30
|
|
|
|
|
106
|
while ($current_node) { |
71
|
177
|
|
|
|
|
1377
|
$handler_object->$handler_method($current_node->data, |
72
|
|
|
|
|
|
|
$current_node,$nodes_so_far++); |
73
|
|
|
|
|
|
|
|
74
|
170
|
|
|
|
|
47058
|
$current_node = $current_node->next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
23
|
|
|
|
|
227
|
return $nodes_so_far; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub delete_node { |
81
|
53
|
|
|
53
|
1
|
973
|
my ($self, $node) = @_; |
82
|
53
|
100
|
|
|
|
183
|
return if not $node; |
83
|
|
|
|
|
|
|
|
84
|
47
|
|
|
|
|
148
|
my $node_data = $node->data; |
85
|
|
|
|
|
|
|
|
86
|
47
|
|
|
|
|
478
|
my $prev_node = $node->prev; |
87
|
47
|
|
|
|
|
363
|
my $next_node = $node->next; |
88
|
|
|
|
|
|
|
|
89
|
47
|
100
|
|
|
|
324
|
if ($prev_node) { |
90
|
42
|
|
|
|
|
122
|
$prev_node->set_next($next_node); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
5
|
|
|
|
|
25
|
$self->set_head($next_node); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
47
|
100
|
|
|
|
286
|
if ($next_node) { |
97
|
41
|
|
|
|
|
132
|
$next_node->set_prev($prev_node); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
47
|
|
|
|
|
246
|
$node->free; |
101
|
|
|
|
|
|
|
|
102
|
47
|
|
|
|
|
217
|
return $node_data; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub DEMOLISH { |
106
|
30
|
|
|
30
|
1
|
16000
|
my ($self) = @_; |
107
|
30
|
|
|
|
|
119
|
my $head = $self->head; |
108
|
30
|
100
|
|
|
|
301
|
if ($head) { |
109
|
27
|
|
|
|
|
152
|
$head->free(); |
110
|
|
|
|
|
|
|
} |
111
|
30
|
|
|
|
|
74
|
undef $self->{__x__head__x__}; # << Class::Dot 1.0 weirdness. |
112
|
30
|
|
|
|
|
62
|
undef $self->{head}; |
113
|
30
|
|
|
|
|
84
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Taken from Params::Util |
117
|
|
|
|
|
|
|
sub _ARRAYLIKE { ## no critic |
118
|
|
|
|
|
|
|
|
119
|
36
|
100
|
66
|
36
|
|
1951
|
(defined $_[0] and ref $_[0] and ( |
120
|
|
|
|
|
|
|
(Scalar::Util::reftype($_[0]) eq 'ARRAY') |
121
|
|
|
|
|
|
|
or |
122
|
|
|
|
|
|
|
overload::Method($_[0], '@{}') |
123
|
|
|
|
|
|
|
)) ? $_[0] : undef; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |