blib/lib/Amon2/Plugin/Web/Streaming.pm

filter: Statementstmt 54.2% 19 / 35 Branchbran n/a Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 1 totaltotal 45.7% 27 / 59 CC 3 SCAR 7.1
CC
3
Cov
51%
init
3.8
_streaming
2.0
__ANON__
2.0
CRAP 2.0
« blib/lib/Amon2.pm ↑ Summary blib/lib/Amon2/Declare.pm »
1 package Amon2::Plugin::Web::Streaming;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Amon2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Amon2::Web::Response::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub init {
Subroutine init: called CC=3 SCAR=13.3
Pod undocumented
10 1 my ($class, $c, $conf) = @_;
11  
12 1 ▶ Amon2::Util::add_method(ref $c || $c, 'streaming', \&_streaming);
Condition33%1/3
ref $c || $c
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $c || $c
ref $c $c
Truth table33%1/3
A || B
A= ref $cB= $c
ABresult
1X1
011
000
13 1 ▶ Amon2::Util::add_method(ref $c || $c, 'streaming_json', \&_streaming_json);
Condition33%1/3
ref $c || $c
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $c || $c
ref $c $c
Truth table33%1/3
A || B
A= ref $cB= $c
ABresult
1X1
011
000
14 }
15  
16 0 ▶sub _streaming {
Subroutine _streaming: not called CC=1 SCAR=6.9
17 0 my ($self, $code) = @_;
18
19 return Amon2::Web::Response::Callback->new(
20 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 $code->(@_);
22 }
23 0 );
24 }
25  
26 0 ▶sub _streaming_json {
Subroutine _streaming_json: not called CC=1 SCAR=6.9
27 0 my ($self, $code) = @_;
28  
29 return Amon2::Web::Response::Callback->new(
30 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 my $respond = shift;
32 0 my $writer = $respond->([200, ['Content-Type' => 'application/json;charset=utf-8']]);
33  
34 0 my $longpoll_ctx = Amon2::Plugin::Web::Streaming::Writer->new(
35 $self,
36 $writer
37 );
38 0 $code->($longpoll_ctx);
39 }
40 0 );
41 }
42  
43 package Amon2::Plugin::Web::Streaming::Writer;
44  
45 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
46 0 my ($class, $c, $writer) = @_;
47 0 bless {ctx => $c, writer => $writer}, $class;
48 }
49  
50 0 ▶sub write_json {
Subroutine write_json: not called CC=1 SCAR=6.9
51 0 my ($self, $data) = @_;
52 0 my $json = $self->{ctx}->render_json($data)->content;
53 0 $self->{writer}->write($json);
54 }
55  
56 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
57 0 my ($self) = @_;
58 0 $self->{writer}->close();
59 }
60  
61 1 1;
62 __END__
« blib/lib/Amon2.pm ↑ Summary blib/lib/Amon2/Declare.pm »