EO

 view release on metacpan or  search on metacpan

lib/EO/Data.pm  view on Meta::CPAN

package EO::Data;

use strict;
use warnings;

use EO;
use NEXT;
use Scalar::Util qw(weaken);
use EO::Hash;
#use EO::Locale;

our $VERSION = 0.96;
our @ISA = qw(EO);

exception EO::Error::InvalidParameter;

sub init {
  my $self = shift;

lib/EO/Data.pm  view on Meta::CPAN



sub add_storage {
  my $self = shift;
  my $storage = shift;
  if (!UNIVERSAL::isa($storage,  'EO::Storage')) {
    throw EO::Error::InvalidParameter
      text => 'storage must be an EO::Storage object';
  }
  $self->{e_data_storage}->{$storage} = $storage;
  weaken($self->{e_data_storage}->{$storage});
  return $self;
}

sub storage {
  my $self = shift;
  if(@_) {
    my $storage = shift;
    if (!UNIVERSAL::isa($storage,  'EO::Storage')) {
      throw EO::Error::InvalidParameter
	text => 'storage must be an EO::Storage object';
    }
    $self->{e_data_storage} = { $storage => $storage };
    weaken( $self->{e_data_storage}->{ $storage } );
    return $self;
  }
  return values %{$self->{e_data_storage}};
}

sub content {
  my $self = shift;
  if(@_) {
    my $content = shift;
    if(ref($content) eq 'SCALAR') {

lib/EO/WeakArray.pm  view on Meta::CPAN

package EO::WeakArray;

use strict;
use warnings;

use EO::Array;
use base qw( EO::Array );
use Scalar::Util qw( weaken );

our $VERSION = 0.96;

sub splice {
  my $self = shift;
  my $result = $self->SUPER::splice(@_);
  my $offset = shift;
  my $length = shift || 0;
  ## in the case that we have an offset we can deal with then we are going
  ## to start weakening the things that we can.  We're not going to be
  ## stupid and walk the entire thing either, no, we'll be smart and only
  ## touch the things that have been touched.
  if ($offset >= 0) {
    for ($offset..$offset + $length) {
      ## can't weaken non-references :-)
      weaken( $self->element->[ $_ ] ) if ref( $self->element->[ $_ ] );
    }
  }
  return $result;
}


sub at {
  my $self = shift;
  if (@_ > 1) {
    ## its a set, so we need to weaken these things.
    my $where = shift;
    my $what  = shift;
    my $result = $self->SUPER::at( $where, $what );
    weaken( $self->element->[ $where ] ) if ref($self->element->[ $where ]);
    return $result;
  } else {
    ## its a get, no weakening needed
    return $self->SUPER::at( @_ );
  }
}

1;

=head1 NAME

EO::WeakArray - arrays where all references contained are weak



( run in 0.364 second using v1.01-cache-2.11-cpan-65fba6d93b7 )