Browse files

Fix Reflex::Role::Collectible's use of type constraints. HDP pointed …

…out that it was bypassing type constraints by using its objects hash directly and explained how to do it correctly.
  • Loading branch information...
1 parent b4f2d19 commit 971a7acf28cd095b8947d1ab54cbd13a3c9e2ed7 @rcaputo committed Oct 14, 2010
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/Reflex/Collection.pm
View
14 lib/Reflex/Collection.pm
@@ -6,6 +6,7 @@ package Reflex::Collection;
use Moose;
use Moose::Exporter;
use Reflex::Callbacks qw(cb_method);
+use Reflex::Role::Collectible;
use Carp qw(cluck);
extends 'Reflex::Base';
@@ -14,24 +15,29 @@ Moose::Exporter->setup_import_methods( with_caller => [ qw( has_many ) ]);
has objects => (
is => 'rw',
- isa => 'HashRef[Reflex::Collectible]',
+ isa => 'HashRef[Reflex::Role::Collectible]',
+ traits => ['Hash'],
default => sub { {} },
+ handles => {
+ _set_object => 'set',
+ _delete_object => 'delete',
+ },
);
sub remember {
my ($self, $object) = @_;
$self->watch($object, stopped => cb_method($self, "cb_forget"));
- $self->objects()->{$object} = $object;
+ $self->_set_object($object, $object);
}
sub forget {
my ($self, $object) = @_;
- delete $self->objects()->{$object};
+ $self->_delete_object($object);
}
sub cb_forget {
my ($self, $args) = @_;
- delete $self->objects()->{$args->{_sender}};
+ $self->_delete_object($args->{_sender});
}
sub has_many {

0 comments on commit 971a7ac

Please sign in to comment.