Ancient
view release on metacpan or search on metacpan
lib/doubly.pm view on Meta::CPAN
=head2 is_end
if ($list->is_end) { ... }
Returns true if the current node is the tail of the list.
=head2 add
$list->add($data);
Adds a new node with the given data at the end of the list.
Returns $self for chaining.
=head2 bulk_add
$list->bulk_add(@items);
Adds multiple items to the end of the list.
Returns $self for chaining.
=head2 insert_before
my $new = $list->insert_before($data);
Inserts a new node before the current node.
Returns a new list object pointing to the inserted node.
=head2 insert_after
my $new = $list->insert_after($data);
Inserts a new node after the current node.
Returns a new list object pointing to the inserted node.
=head2 insert_at_start
my $new = $list->insert_at_start($data);
Inserts a new node at the beginning of the list.
Returns a new list object pointing to the inserted node.
=head2 insert_at_end
my $new = $list->insert_at_end($data);
Inserts a new node at the end of the list.
Returns a new list object pointing to the inserted node.
=head2 insert_at_pos
my $new = $list->insert_at_pos($pos, $data);
Inserts a new node at the specified position.
Returns a new list object pointing to the inserted node.
=head2 remove
my $data = $list->remove;
Removes the current node and returns its data.
The list object is updated to point to the next (or previous) node.
=head2 remove_from_start
my $data = $list->remove_from_start;
Removes the head node and returns its data.
=head2 remove_from_end
my $data = $list->remove_from_end;
Removes the tail node and returns its data.
=head2 remove_from_pos
my $data = $list->remove_from_pos($pos);
Removes the node at the specified position and returns its data.
=head2 find
my $found = $list->find(sub { $_[0] eq "target" });
Searches for a node matching the callback.
Returns a new list object pointing to the found node, or undef if not found.
=head2 insert
$list->insert(sub { $_[0] > $value }, $data);
Inserts data before the first node where the callback returns true.
If no match is found, inserts at the end.
Returns $self.
=head2 destroy
$list->destroy;
Explicitly destroys the list and frees all nodes.
=head1 THREADS
B<This module is NOT thread-safe.> Lists cannot be shared across threads.
When a new thread is created, any C<doubly> objects in scope will become
unblessed references in the child thread and cannot be used. Each thread
must create its own lists.
use threads;
use doubly;
my $list = doubly->new();
$list->add(42);
my $t = threads->create(sub {
# $list is an unblessed reference here - cannot use it!
# Create a new list in this thread instead:
my $thread_list = doubly->new();
$thread_list->add(1);
return $thread_list->length;
( run in 0.811 second using v1.01-cache-2.11-cpan-df04353d9ac )