Set::Object::Weak - Sets without the referant reference increment


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

Index


Code Index:

NAME

Top

Set::Object::Weak - Sets without the referant reference increment

SYNOPSIS

Top

 use Set::Object::Weak qw(weak_set);

 my $set = Set::Object::Weak->new( 0, "", {}, [], $object );
 # or
 my $set = weak_set( 0, "", {}, [], $object );

 print $set->size;  # 2 - the scalars aren't objects

DESCRIPTION

Top

Sets, but weak. See weaken in Set::Object.

Note that the set in Set::Object::Weak returns weak sets. This is intentional, so that you can make all the sets in scope weak just by changing use Set::Object to use Set::Object::Weak.

CONSTRUCTORS

Top

new

This class method is exactly the same as Set::Object->new, except that it returns a weak set.

weak_set( ... )

This optionally exported function is a shortcut for saying Set::Object::Weak->new(...).

set( ... )

This method is exported so that if you see:

 use Set::Object qw(set);

You can turn it into using weak sets lexically with:

 use Set::Object::Weak qw(set);

Set::Object 1.19 had a bug in this method that meant that it would not add the passed members into it.

SEE ALSO

Top

Set::Object

CREDITS

Top

Perl magic by Sam Vilain, <samv@cpan.org>

Idea from nothingmuch.


Set-Object documentation Contained in the Set-Object distribution.
package Set::Object::Weak;

use base qw(Set::Object);  # boo hiss no moose::role yet I hear you say

use base qw(Exporter);     # my users would hate me otherwise
use vars qw(@ISA @EXPORT_OK);
use Set::Object qw(blessed);

our @EXPORT_OK = qw(weak_set set);

sub new {
    my $class = shift;
    my $self = $class->SUPER::new();
    $self->weaken;
    $self->insert(@_);
    $self;
}


sub weak_set {
    __PACKAGE__->new(@_);
}

sub set {
    my $class = __PACKAGE__;
    if (blessed $_[0] and $_[0]->isa("Set::Object")) {
    	$class = (shift)->strong_pkg;
    }
    $class->new(@_);
}

1;

__END__