Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make SubscriptionRegistry::_subscriptions into a set too

  • Loading branch information...
commit fc164c14b82753d9db1d376143cd15fcbb6d25c2 1 parent f40f7d4
@pdcawley authored
Showing with 11 additions and 17 deletions.
  1. +11 −17 lib/Announcements/SubscriptionRegistry.pm
View
28 lib/Announcements/SubscriptionRegistry.pm
@@ -1,18 +1,18 @@
package Announcements::SubscriptionRegistry;
use Moose;
use Announcements::Subscription;
+use Announcements::Types qw(SubscriptionSet);
has _subscriptions => (
- traits => ['Array'],
is => 'ro',
- isa => 'ArrayRef[Announcements::Subscription]',
- default => sub { [] },
+ isa => SubscriptionSet,
+ default => sub { to_SubscriptionSet([]) },
+ coerce => 1,
lazy => 1,
handles => {
- subscriptions => 'elements',
- _add_subscription => 'push',
- _delete_subscription => 'delete',
- _index_of_subscription => 'first_index',
+ _add_subscription => 'insert',
+ _delete_subscription => 'remove',
+ _foreach_subscription => 'each',
},
);
@@ -25,8 +25,6 @@ sub add_subscription {
$subscription = Announcements::Subscription->new(@_);
}
- return $subscription if $subscription->is_in($self);
-
$self->_add_subscription($subscription);
$subscription->_join_registry($self);
@@ -40,19 +38,15 @@ sub announce {
$announcement = $announcement->as_announcement;
- for my $subscription ($self->subscriptions) {
- $subscription->send($announcement, $announcer);
- }
+ $self->_foreach_subscription(sub {
+ $_->send($announcement, $announcer);
+ });
}
sub unsubscribe {
my $self = shift;
my $subscription = shift;
- $self->_delete_subscription(
- $self->_index_of_subscription(sub {
- $_ == $subscription;
- })
- );
+ $self->_delete_subscription( $subscription );
$subscription->_leave_registry($self);
}
Please sign in to comment.
Something went wrong with that request. Please try again.