Getopt-LL

 view release on metacpan or  search on metacpan

lib/Getopt/LL/DLList/Node.pm  view on Meta::CPAN

# $Id: Node.pm,v 1.9 2007/07/13 00:00:15 ask Exp $
# $Source: /opt/CVS/Getopt-LL/lib/Getopt/LL/DLList/Node.pm,v $
# $Author: ask $
# $HeadURL$
# $Revision: 1.9 $
# $Date: 2007/07/13 00:00:15 $
package Getopt::LL::DLList::Node;
use strict;
use warnings;
use Carp;
use Scalar::Util qw( weaken );
use version; our $VERSION = qv('1.0.0');
use 5.006_001;
{

    use vars qw($ALLOCATED_TOTAL);
    $ALLOCATED_TOTAL = 0;

    use Class::Dot qw( property isa_Object isa_Data );
    property    prev => isa_Object();
    property    next => isa_Object();
    property    data => isa_Data;

    sub new {
        my ($class, $opt_data) = @_;

        $ALLOCATED_TOTAL++;

        my $self = bless {}, $class;

        if ($opt_data) {
            $self->set_data($opt_data);
        }

        return $self;
    }

    sub free {
        my ($self) = @_;
        my $next = $self->next;
        my $prev = $self->prev;
        weaken $next;
        weaken $prev;
        undef $self->{next};
        undef $self->{prev};
        undef $self->{data};

        # Class::Dot 1.0 weirdness.
        undef $self->{__x__next__x__};
        undef $self->{__x__prev__x__};
        undef $self->{__x__data__x__};
        return;
    }

    sub DEMOLISH {
        $ALLOCATED_TOTAL--;
        return;
    }

    sub END {
        my ($self) = @_;

        #if ($ALLOCATED_TOTAL) {
        #    carp "DLList::Node Warning: There were $ALLOCATED_TOTAL nodes "
        #        .'not properly freed during destruction.';
        #}

    }

}
1;

__END__

=for stopwords expandtab shiftround

=begin wikidoc

= NAME

Getopt::LL::DLList::Node - Node in a doubly linked list.

= VERSION

This document describes Getopt::LL::DLList::Node version %%VERSION%%

= SYNOPSIS


= DESCRIPTION

    use Getopt:LL::DLList::Node;

    my $head_node   = Getopt::LL::DLList::Node->new('top');
    my $middle_node = Getopt::LL::DLList::Node->new('middle');
    my $bottom_node = Getopt::LL::DLList::Node->new('bottom');

    $head_node->set_next(   $middle_node );
    $middle_node->set_prev( $head_node   );
    $middle_node->set_next( $bottom_node );
    $bottom_node->set_prev( $middle_node );

    my $current_node = $head_node;



( run in 0.727 second using v1.01-cache-2.11-cpan-39bf76dae61 )