Pusher/Channel.pm

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