Skip to content

Commit

Permalink
Fix Reflex::Role::Collectible's use of type constraints. HDP pointed …
Browse files Browse the repository at this point in the history
…out that it was bypassing type constraints by using its objects hash directly and explained how to do it correctly.
  • Loading branch information
rcaputo committed Oct 14, 2010
1 parent b4f2d19 commit 971a7ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Reflex/Collection.pm
Expand Up @@ -6,6 +6,7 @@ package Reflex::Collection;
use Moose; use Moose;
use Moose::Exporter; use Moose::Exporter;
use Reflex::Callbacks qw(cb_method); use Reflex::Callbacks qw(cb_method);
use Reflex::Role::Collectible;
use Carp qw(cluck); use Carp qw(cluck);


extends 'Reflex::Base'; extends 'Reflex::Base';
Expand All @@ -14,24 +15,29 @@ Moose::Exporter->setup_import_methods( with_caller => [ qw( has_many ) ]);


has objects => ( has objects => (
is => 'rw', is => 'rw',
isa => 'HashRef[Reflex::Collectible]', isa => 'HashRef[Reflex::Role::Collectible]',
traits => ['Hash'],
default => sub { {} }, default => sub { {} },
handles => {
_set_object => 'set',
_delete_object => 'delete',
},
); );


sub remember { sub remember {
my ($self, $object) = @_; my ($self, $object) = @_;
$self->watch($object, stopped => cb_method($self, "cb_forget")); $self->watch($object, stopped => cb_method($self, "cb_forget"));
$self->objects()->{$object} = $object; $self->_set_object($object, $object);
} }


sub forget { sub forget {
my ($self, $object) = @_; my ($self, $object) = @_;
delete $self->objects()->{$object}; $self->_delete_object($object);
} }


sub cb_forget { sub cb_forget {
my ($self, $args) = @_; my ($self, $args) = @_;
delete $self->objects()->{$args->{_sender}}; $self->_delete_object($args->{_sender});
} }


sub has_many { sub has_many {
Expand Down

0 comments on commit 971a7ac

Please sign in to comment.