| 1 | package PubNub::PubSub; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Mojo::JSON qw/encode_json/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Mojo::Util qw/url_escape/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use PubNub::PubSub::Message; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | $args{host} ||= 'pubsub.pubnub.com'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"host"} ||= "pubsub.pubnub.com"
MC/DC0%0/1
$args{"host"} ||= "pubsub.pubnub.com"
$args{"host"}
Truth table50%1/2
A
A= $args{"host"}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | $args{port} ||= 80; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"port"} ||= 80
MC/DC0%0/1
$args{"port"} ||= 80
$args{"port"}
Truth table50%1/2
A
A= $args{"port"}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | $args{timeout} ||= 60; # for ua timeout | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"timeout"} ||= 60
MC/DC0%0/1
$args{"timeout"} ||= 60
$args{"timeout"}
Truth table50%1/2
A
A= $args{"timeout"}
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | $args{publish_queue} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"publish_queue"} ||= []
MC/DC0%0/1
$args{"publish_queue"} ||= []
$args{"publish_queue"}
Truth table50%1/2
A
A= $args{"publish_queue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $proto = ($args{port} == 443) ? 'https://' : 'http://'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | $args{web_host} ||= $proto . $args{host}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"web_host"} ||= $proto . $args{"host"}
MC/DC0%0/2
$args{"web_host"} ||= $proto . $args{"host"}
$args{"web_host"}
$proto . $args{"host"}
Truth table33%1/3
A ||= B
A= $args{"web_host"}B= $proto . $args{"host"}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub __ua { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ua: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return $self->{ua} if exists $self->{ua}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $ua = Mojo::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $ua->max_redirects(3); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $ua->inactivity_timeout($self->{timeout}); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $ua->proxy->detect; # env proxy | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $ua->cookie_jar(0); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $ua->max_connections(100); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->{ua} = $ua; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return $ua; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub publish { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publish: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $callback = $params{callback} || $self->{publish_callback}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params{'callback'} || $self->{'publish_callback'}
MC/DC0%0/2
$params{'callback'} || $self->{'publish_callback'}
$params{'callback'}
$self->{'publish_callback'}
Truth table0%0/3
A || B
A= $params{'callback'}B= $self->{'publish_callback'}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $ua = $self->__ua; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | my @steps = map { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $ref = $_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $url = $ref->{url}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $delay = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $end = $delay->begin; | |||||||||||||||||||||||||||||||||||||||||
| 61 | $ua->get( | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $url => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $callback->($_[1]->res, $ref->{message}) if $callback; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $end->(); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | } $self->__construct_publish_urls(%params); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return Mojo::IOLoop->delay(@steps)->wait; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub __construct_publish_urls { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__construct_publish_urls: called CC=8 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | my $pub_key = $params{pub_key} || $self->{pub_key}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{'pub_key'} || $self->{'pub_key'}
MC/DC0%0/2
$params{'pub_key'} || $self->{'pub_key'}
$params{'pub_key'}
$self->{'pub_key'}
Truth table33%1/3
A || B
A= $params{'pub_key'}B= $self->{'pub_key'}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | $pub_key or croak "pub_key is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | my $sub_key = $params{sub_key} || $self->{sub_key}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{'sub_key'} || $self->{'sub_key'}
MC/DC0%0/2
$params{'sub_key'} || $self->{'sub_key'}
$params{'sub_key'}
$self->{'sub_key'}
Truth table33%1/3
A || B
A= $params{'sub_key'}B= $self->{'sub_key'}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | $sub_key or croak "sub_key is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | my $channel = $params{channel} || $self->{channel}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{'channel'} || $self->{'channel'}
MC/DC0%0/2
$params{'channel'} || $self->{'channel'}
$params{'channel'}
$self->{'channel'}
Truth table33%1/3
A || B
A= $params{'channel'}B= $self->{'channel'}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | $channel or croak "channel is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | $params{messages} or croak "messages is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | return map { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my $json = $_->json; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | my $uri = Mojo::URL->new($self->{web_host} . qq~/publish/$pub_key/$sub_key/0/$channel/0/~ . url_escape($json)); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | $uri->query($_->query_params(\%params)); | |||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | url => $uri->to_string, | |||||||||||||||||||||||||||||||||||||||||
| 89 | message => $_ | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } map { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | PubNub::PubSub::Message->new($_) | |||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | } @{$params{messages}}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub subscribe { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subscribe: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $sub_key = $params{sub_key} || $self->{sub_key}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params{'sub_key'} || $self->{'sub_key'}
MC/DC0%0/2
$params{'sub_key'} || $self->{'sub_key'}
$params{'sub_key'}
$self->{'sub_key'}
Truth table0%0/3
A || B
A= $params{'sub_key'}B= $self->{'sub_key'}
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $sub_key or croak "sub_key is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $channel = $params{channel} || $self->{channel}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params{'channel'} || $self->{'channel'}
MC/DC0%0/2
$params{'channel'} || $self->{'channel'}
$params{'channel'}
$self->{'channel'}
Truth table0%0/3
A || B
A= $params{'channel'}B= $self->{'channel'}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $channel or croak "channel is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $callback = $params{callback} or croak "callback is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $timetoken = $params{timetoken} || '0'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params{'timetoken'} || '0'
MC/DC0%0/1
$params{'timetoken'} || '0'
$params{'timetoken'}
Truth table0%0/2
A
A= $params{'timetoken'}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $ua = $self->__ua; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $tx = $ua->get($self->{web_host} . "/subscribe/$sub_key/$channel/0/$timetoken"); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | unless ($tx->success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | # for example $tx->error->{message} =~ /Inactivity timeout/ | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # This is not a traditional goto. Instead it exits this function | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # and re-enters with @ as params. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # see goto docs, this is basically a method call which exits the current | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # function first. So no extra call stack depth. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | @_ = ($self, %params, timetoken => $timetoken); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | goto &subscribe; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $json = $tx->res->json; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my @cb_args = $params{raw_msg} ? ($json) : (@{$json->[0]}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $rtn = $callback ? $callback->(@cb_args) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return unless $rtn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $timetoken = $json->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return $self->subscribe(%params, timetoken => $timetoken); | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub subscribe_multi { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subscribe_multi: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | croak 'channels must be an arrayref' | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | unless ref($params{channels}) =~ /ARRAY/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | croak 'callback must be a hashref or coderef' | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | unless ref($params{callback}) =~ /(HASH|CODE)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $callback; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (ref($params{callback}) =~ /HASH/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | for (keys %{$params{callback}}) { | |||||||||||||||||||||||||||||||||||||||||
| 144 | croak "Non-coderef value found for callback key $_" | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | unless ref($params{callback}->{$_}) =~ /CODE/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $callback = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my ($obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my (undef, undef, $channel) = @$obj; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $cb_dispatch = $params{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | unless ($channel) { # on connect messages | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | goto $cb_dispatch->{on_connect} | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if exists $cb_dispatch->{on_connect}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if (exists $cb_dispatch->{$channel}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # these are verified coderefs, so replacing the current stack | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # frame with a call to the function. They will *not* jump to | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # a label or other points. Basically this just lets us pretend | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # that this was called directly by subscribe above. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | goto $cb_dispatch->{$channel}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } elsif (exists $cb_dispatch->{'_default'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | goto $cb_dispatch->{_default}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | warn 'Using callback dispatch table, cannot find channel callback' . ' and _default callback not specified'; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $callback = $params{callback} unless ref $callback; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $channel_string = join ',', @{$params{channels}}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return $self->subscribe( | |||||||||||||||||||||||||||||||||||||||||
| 175 | channel => $channel_string, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | callback => $callback, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | raw_msg => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub history { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
history: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if (scalar(@_) == 1 and ref($_[0]) ne 'HASH' and $_[0] =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
scalar @_ == 1 and ref $_[0] ne "HASH" and $_[0] =~ /^\d+$/
scalar @_ == 1 and ref $_[0] ne "HASH"
MC/DC0%0/3
scalar @_ == 1 and ref $_[0] ne "HASH" and $_[0] =~ /^\d+$/
scalar @_ == 1
ref $_[0] ne "HASH"
$_[0] =~ /^\d+$/
Truth table0%0/4
A and B and C
A= scalar @_ == 1B= ref $_[0] ne "HASH"C= $_[0] =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | @_ = (count => $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | warn "->history(\$num) is deprecated and will be removed in next few releases.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $sub_key = delete $params{sub_key} || $self->{sub_key}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
delete $params{'sub_key'} || $self->{'sub_key'}
MC/DC0%0/2
delete $params{'sub_key'} || $self->{'sub_key'}
delete $params{'sub_key'}
$self->{'sub_key'}
Truth table0%0/3
A || B
A= delete $params{'sub_key'}B= $self->{'sub_key'}
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $sub_key or croak "sub_key is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $channel = delete $params{channel} || $self->{channel}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
delete $params{'channel'} || $self->{'channel'}
MC/DC0%0/2
delete $params{'channel'} || $self->{'channel'}
delete $params{'channel'}
$self->{'channel'}
Truth table0%0/3
A || B
A= delete $params{'channel'}B= $self->{'channel'}
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $channel or croak "channel is required."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $ua = $self->__ua; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $tx = $ua->get($self->{web_host} . "/v2/history/sub-key/$sub_key/channel/$channel" => form => \%params); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return [$tx->error->{message}] unless $tx->success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return $tx->res->json; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 204 | __END__ | ||||||||||||||||||||||||||||||||||||||||||