Pusher.pm

filter: Statementstmt 83.3% 15 / 18 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 74.0% 20 / 27 CC 2 SCAR 9.8
CC
2
Cov
75%
connect
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Pusher/Channel.pm ↑ Summary
1 package Net::Async::Pusher;
2 # ABSTRACT: use pusher.com with IO::Async
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.005';
7 1 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 1 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Net::Async::Pusher - support for pusher.com streaming event API
14  
15 =head1 SYNOPSIS
16  
17 #!/usr/bin/env perl
18 use strict;
19 use warnings;
20 use feature qw(say);
21 # For more details, enable this
22 # use Log::Any::Adapter qw(Stdout);
23 use IO::Async::Loop;
24 use Net::Async::Pusher;
25 my $loop = IO::Async::Loop->new;
26 $loop->add(
27 my $pusher = Net::Async::Pusher->new
28 );
29 say "Connecting to pusher.com via websocket...";
30 my $sub = $pusher->connect(
31 key => 'de504dc5763aeef9ff52'
32 )->then(sub {
33 my ($conn) = @_;
34 say "Connection established. Opening channel.";
35 $conn->open_channel('live_trades')
36 })->then(sub {
37 my ($ch) = @_;
38 say "Have channel, setting up event handler for 'trade' event.";
39 $ch->subscribe(trade => sub {
40 my ($ev, $data) = @_;
41 say "New trade - price " . $data->{price} . ", amount " . $data->{amount};
42 });
43 })->get;
44 say "Subscribed and waiting for events...";
45 $loop->run;
46 $sub->()->get;
47  
48 =head1 DESCRIPTION
49  
50 Provides basic integration with the L<https://pusher.com|Pusher> API.
51  
52 =cut
53  
54 1 ▶use Net::Async::Pusher::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 =head2 connect
57  
58 Connects to a server using a key.
59  
60 my $conn = $pusher->connect(
61 key => 'abc123'
62 )->get;
63  
64 Resolves to a L<Net::Async::Pusher::Connection>.
65  
66 =cut
67  
68 0 ▶sub connect {
Subroutine connect: not called CC=2 SCAR=17.9
Pod documented
69 0 my ($self, %args) = @_;
70 $self->add_child(
71 my $conn = Net::Async::Pusher::Connection->new(
72 0 ▶ key => $args{key} // die "need a key"
Condition0%0/2
$args{"key"} // die("need a key")
l!l
00
MC/DC0%0/1
$args{"key"} // die("need a key")
$args{"key"}
Truth table0%0/2
A
A= $args{"key"}
Aresult
11
00
73 )
74 );
75 0 $conn->connect
76 }
77  
78 1 1;
79  
80 __END__
« Pusher/Channel.pm ↑ Summary