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