Set::Scalar::Universe - universes for set members


Set-Scalar documentation Contained in the Set-Scalar distribution.

Index


Code Index:

NAME

Top

Set::Scalar::Universe - universes for set members

SYNOPSIS

Top

Do not use directly.

DESCRIPTION

Top

There are only two guaranteed interfaces, both sort of indirect.

The first one is accessing the universe of a set:

    $set->universe

This contains the members of the universe

    $set->universe->members

of the $set.

The second supported interface is displaying set universes.

    print $set->universe, "\n";

This will display the members of the set inside square brackets: [], as opposed to sets, which have their members shown inside parentheses: ().

AUTHOR

Top

Jarkko Hietaniemi <jhi@iki.fi>


Set-Scalar documentation Contained in the Set-Scalar distribution.

package Set::Scalar::Universe;

use strict;
local $^W = 1;

use vars qw(@ISA);

@ISA = qw(Set::Scalar::Virtual Set::Scalar::Base);

use Set::Scalar::Base qw(_make_elements);
use Set::Scalar::Virtual;
use Set::Scalar::Null;

use overload
    'neg'	=> \&_complement_overload;

my $UNIVERSE = __PACKAGE__->new;

sub SET_FORMAT        { "[%s]" }

sub universe {
    my $self = shift;

    return $UNIVERSE;
}

sub null {
    my $self = shift;

    return $self->{'null'};
}

sub enter {
    my $self = shift;

    $UNIVERSE = $self;
}

sub _new_hook {
    my $self     = shift;
    my $elements = shift;

    $self->{'universe'} = $UNIVERSE;
    $self->{'null'    } = Set::Scalar::Null->new( $self );

    $self->_extend( { _make_elements( @$elements ) } );
}

sub _complement_overload {
    my $self = shift;

    return Set::Scalar::Null->new( $self );
}

1;