Pusher/Channel.pm

filter: Statementstmt 43.5% 27 / 62 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 44.4% 8 / 18 Podpod 25.0% 2 / 8 totaltotal 30.8% 37 / 120 CC 12 SCAR 19.3
CC
12
Cov
31%
incoming_message
20.0
configure
12.0
bus
6.0
CRAP 6.9
« Pusher/Connection.pm ↑ Summary Pusher.pm »
1 package Net::Async::Pusher::Channel;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.005'; # VERSION
9 3 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
10  
11 =head1 NAME
12  
13 Net::Async::Pusher::Channel - represents a channel on a L<Net::Async::Pusher::Connection>.
14  
15 =head1 DESCRIPTION
16  
17 Provides basic integration with the L<https://pusher.com|Pusher> API.
18  
19 =cut
20  
21 3 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Mixin::Event::Dispatch::Bus;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Ryu::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 3 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 0 ▶sub configure {
Subroutine configure: not called CC=3 SCAR=24.8
Pod documented
29 0 my ($self, %args) = @_;
30 0 for (qw(name)) {
31 0 ▶ $self->{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
32 }
33 0 return $self->SUPER::configure(%args);
34 }
35  
36 0 ▶sub bus { shift->{bus} //= Mixin::Event::Dispatch::Bus->new }
Subroutine bus: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
+(shift())->{"bus"} //= "Mixin::Event::Dispatch::Bus"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"bus"} //= "Mixin::Event::Dispatch::Bus"->new
+(shift())->{"bus"} "Mixin::Event::Dispatch::Bus"->new
Truth table0%0/3
A //= B
A= +(shift())->{"bus"}B= "Mixin::Event::Dispatch::Bus"->new
ABresult
1X1
011
000
37 0 ▶sub json { shift->{json} //= JSON::MaybeXS->new( allow_nonref => 1) }
Subroutine json: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
+(shift())->{"json"} //= "JSON::MaybeXS"->new("allow_nonref", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"json"} //= "JSON::MaybeXS"->new("allow_nonref", 1)
+(shift())->{"json"} "JSON::MaybeXS"->new("allow_nonref", 1)
Truth table0%0/3
A //= B
A= +(shift())->{"json"}B= "JSON::MaybeXS"->new("allow_nonref", 1)
ABresult
1X1
011
000
38  
39 0 ▶sub ryu { shift->{ryu} }
Subroutine ryu: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 0 ▶sub subscribe {
Subroutine subscribe: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my ($self) = shift;
43 0 my @sub;
44 0 ▶ while(my ($k, $v) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
45 0 $k = "event::$k";
46 0 $self->bus->subscribe_to_event($k => $v);
47 0 push @sub, $k => $v;
48 }
49 0 ▶ Future->done(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 ▶ while(my ($k, $v) = splice @sub, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@sub, 0, 2)) 0 0 0
51 try {
52 0 $self->bus->unsubscribe_from_event($k => $v);
53 0 } catch {
54 0 $log->errorf('Failed to unsubscribe from %s - %s', $k, $@);
55 }
56 }
57 0 Future->done;
58 })
59 0 }
60  
61 0 ▶sub incoming_message {
Subroutine incoming_message: not called CC=4 SCAR=30.0
Pod undocumented
62 0 my ($self, $info) = @_;
63 0 ▶ if($info->{event} eq 'pusher_internal:subscription_succeeded') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{'event'} eq 'pusher_internal:subscription_succeeded') { } 0 0 0
64 0 return $self->subscribed->done
65 } else {
66 try {
67 0 my $data = $self->json->decode($info->{data});
68 0 ▶ if(my $bus = $self->{bus}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bus = $self->{"bus"}) 0 0 0
69 $self->bus->invoke_event(
70 0 "event::" . $info->{event} => $data
71 );
72 }
73 0 ▶ if(my $src = $self->{source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $src = $self->{"source"}) 0 0 0
74 0 $src->emit($info);
75 }
76 1
77 0 } catch {
78 0 $log->errorf("Exception [%s] on %s", $@, $info->{data});
79 }
80 }
81 }
82  
83 0 ▶sub subscribed { $_[0]->{subscribed} //= $_[0]->loop->new_future }
Subroutine subscribed: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
$_[0]{"subscribed"} //= $_[0]->loop->new_future
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"subscribed"} //= $_[0]->loop->new_future
$_[0]{"subscribed"} $_[0]->loop->new_future
Truth table0%0/3
A //= B
A= $_[0]{"subscribed"}B= $_[0]->loop->new_future
ABresult
1X1
011
000
84  
85 =head2 source
86  
87 Returns a L<Ryu::Source> which will emit an item for each event on the channel.
88  
89 =cut
90  
91 0 ▶sub source {
Subroutine source: not called CC=2 SCAR=17.9
Pod documented
92 0 my ($self) = @_;
93 0 ▶ $self->{source} //= $self->ryu->source
Condition0%0/3
$self->{"source"} //= $self->ryu->source
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"source"} //= $self->ryu->source
$self->{"source"} $self->ryu->source
Truth table0%0/3
A //= B
A= $self->{"source"}B= $self->ryu->source
ABresult
1X1
011
000
94 }
95  
96 0 ▶sub _add_to_loop {
Subroutine _add_to_loop: not called CC=1 SCAR=6.9
97 0 my ($self) = @_;
98 $self->add_child(
99 0 $self->{ryu} = Ryu::Async->new
100 )
101 }
102  
103 3 1;
104  
105 __END__
« Pusher/Connection.pm ↑ Summary Pusher.pm »