| 1 | package Net::Async::Redis::Subscription; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 15 | our $VERSION = '6.006'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Net::Async::Redis::Subscription - represents one subscription | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Instances are generated by the subscription methods such as L<Net::Async::Redis/subscribe> | ||||||||||||||||||||||||||||
| 15 | and L<Net::Async::Redis/psubscribe>. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 15 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | weaken($args{redis} // die 'Must be provided a Net::Async::Redis instance'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"redis"} // die("Must be provided a Net::Async::Redis instance")
MC/DC0%0/1
$args{"redis"} // die("Must be provided a Net::Async::Redis instance")
$args{"redis"}
Truth table0%0/2
A
A= $args{"redis"}
| |||||||||||||||||||||||||||||
| 24 | 0 | bless \%args, $class; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head2 events | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Returns a L<Ryu::Source> representing the messages emitted by this subscription. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub events { | ||||||||||||||||||||||||||
|
Subroutine
events: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $self->{events} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$$self{"events"} ||= do {
my $ryu = $self->redis->ryu->source("label", $self->channel);
$ryu->completed->on_ready(sub {
builtin::weaken($self);
}
);
$ryu
}
MC/DC0%0/2
$$self{"events"} ||= do {
my $ryu = $self->redis->ryu->source("label", $self->channel);
$ryu->completed->on_ready(sub {
builtin::weaken($self);
}
);
$ryu
}
$$self{"events"}
do {
my $ryu = $self->redis->ryu->source("label", $self->channel);
$ryu->completed->on_ready(sub {
builtin::weaken($self);
}
);
$ryu
}
Truth table0%0/3
A ||= B
A= $$self{"events"}B= do {
my $ryu = $self->redis->ryu->source("label", $self->channel);
$ryu->completed->on_ready(sub {
builtin::weaken($self);
}
);
$ryu
}
| |||||||||||||||||||||||||||||
| 36 | 0 | my $ryu = $self->redis->ryu->source( | |||||||||||||||||||||||||||
| 37 | label => $self->channel | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $ryu->completed->on_ready(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 40 | 0 | weaken $self | |||||||||||||||||||||||||||
| 41 | 0 | }); | |||||||||||||||||||||||||||
| 42 | 0 | $ryu | |||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 cancel | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Cancel an existing subscription. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Normally called by L<Net::Async::Redis> itself once the subscription is no longer valid. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub cancel { | ||||||||||||||||||||||||||
|
Subroutine
cancel: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | my $ev = $self->events; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | $ev->fail('cancelled') unless $ev->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $self | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 redis | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Accessor for the L<Net::Async::Redis> instance. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub redis { shift->{redis} } | ||||||||||||||||||||||||||
|
Subroutine
redis: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 channel | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | The channel name for this instance. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub channel { shift->{channel} } | ||||||||||||||||||||||||||
|
Subroutine
channel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT' or not my $ev = $self->{events}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${^GLOBAL_PHASE} eq "DESTRUCT" or not my $ev = $$self{"events"}
MC/DC0%0/2
${^GLOBAL_PHASE} eq "DESTRUCT" or not my $ev = $$self{"events"}
${^GLOBAL_PHASE} eq "DESTRUCT"
not my $ev = $$self{"events"}
Truth table0%0/3
A or not(B)
A= ${^GLOBAL_PHASE} eq "DESTRUCT"B= not my $ev = $$self{"events"}
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $ev->completed->done unless $ev->completed->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 15 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||