Skip to content

Commit

Permalink
Made subscription a bit more picky about its arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcawley committed Nov 4, 2011
1 parent c396108 commit 31807a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Announcements/Subscription.pm
Expand Up @@ -35,6 +35,9 @@ sub BUILDARGS {
my $params = $class->SUPER::BUILDARGS(@_);

if (my $oneshot = delete $params->{do_once}) {
die "You can use 'do', or you can use 'do_once'. You cannot use both"
if $params->{do};

$params->{do} = sub {
$_[2]->unsubscribe;
$oneshot->(@_);
Expand Down
17 changes: 16 additions & 1 deletion t/unsubscribing.t
Expand Up @@ -2,6 +2,7 @@ use Test::More;
use strict;
use warnings;
use Announcements::Subscription;
use Test::Fatal;

{
package PushedButton;
Expand Down Expand Up @@ -40,7 +41,7 @@ subtest "Basic unsubscription" => sub {
is $announcement_count, 1;
};

subtest "Basic unsubscription" => sub {
subtest "do_once" => sub {
my $nuke = PushedButton->new;
my $announcement_count = 0;

Expand All @@ -57,6 +58,20 @@ subtest "Basic unsubscription" => sub {
is $announcement_count, 1;
};

subtest "Do, or do_once, there is no confusion" => sub {
isnt(
exception {
Announcements::Subscription->new(
when => 'PushedButton',
do => sub { 'one thing' },
do_once => sub { 'or the other' },
)
},
undef,
"Two params enter, one param leaves"
)
};

subtest "Double subscription is wrong, m'kay?" => sub {
my $nuke = PushedButton->new;
my $announcement_count = 0;
Expand Down

0 comments on commit 31807a5

Please sign in to comment.