Getopt::LL::DLList::Node


Getopt-LL documentation Contained in the Getopt-LL distribution.

Index


Code Index:

# Local Variables: # mode: cperl # cperl-indent-level: 4 # fill-column: 78 # End: # vim: expandtab tabstop=4 shiftwidth=4 shiftround


Getopt-LL documentation Contained in the Getopt-LL distribution.

# $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__