Neaf/Request/FakeWriter.pm

filter: Statementstmt 100% 21 / 21 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 91.8% 34 / 37 CC 3 SCAR 3.7
CC
3
Cov
92%
respond
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.5
« Neaf/X/Session/Cookie.pm ↑ Summary Neaf/View.pm »
1 package MVC::Neaf::Request::FakeWriter;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 our $VERSION = '0.2901';
6  
7 =head1 NAME
8  
9 MVC::Neaf::Request::FakeWriter - part of test suite for Not Even A Framework
10  
11 =head1 DESCRIPTION
12  
13 See L<MVC::Neaf> and L<MVC::Neaf::Request::PSGI>.
14 Unless you plan to contribute to framework itself, this module is useless.
15  
16 This module converts L<PSGI> asynchronous response with callback to a normal
17 straightforward response ([status, header, content]).
18  
19 =head1 SINOPSYS
20  
21 use Data::Dumper;
22 use MVC::Neaf::Request::FakeWriter;
23  
24 my $capture = MVC::Neaf::Request::FakeWriter->new;
25 my $result = $capture->respond( $psgi_app_return );
26 warn Dumper( $result ); # normal PSGI response
27 # aka [ status, [ head...], [content...] ]
28  
29 =head1 METHODS
30  
31 =head2 new
32  
33 Constructor (no args).
34  
35 =head2 respond( sub { ... } )
36  
37 Respond to provided callback in PSGI-compatible manner.
38  
39 =head2 write( $data )
40  
41 Append given data to buffer.
42  
43 =head2 close()
44  
45 Do nothing.
46  
47 =cut
48  
49 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
50 5 return bless {}, shift;
51 };
52  
53 5 ▶sub respond {
Subroutine respond: called CC=2 SCAR=7.0
Pod documented
54 5 my ($self, $psgi_ret) = @_;
55  
56 5 ▶ return $psgi_ret if ref $psgi_ret eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $psgi_ret eq "ARRAY" 0 5 5
57  
58 5 ▶ $psgi_ret->( sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
59 5 my $resp = shift;
60 5 $self->{status} = $resp->[0];
61 5 $self->{header} = $resp->[1];
62 5 ▶ $self->{content} = $resp->[2] || [];
Condition50%1/2
$resp->[2] || []
l!l
05
MC/DC0%0/1
$resp->[2] || []
$resp->[2]
Truth table50%1/2
A
A= $resp->[2]
Aresult
11
00
63  
64 5 return $self;
65 5 } );
66  
67 5 return [ $self->{status}, $self->{header}, $self->{content} ];
68 };
69  
70 49 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod documented
71 49 my ($self, $data) = @_;
72 49 push @{ $self->{content} }, $data;
73 };
74  
75 7 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
76 };
77  
78 =head1 LICENSE AND COPYRIGHT
79  
80 This module is part of L<MVC::Neaf> suite.
81  
82 Copyright 2016-2023 Konstantin S. Uvarin C<khedin@cpan.org>.
83  
84 This program is free software; you can redistribute it and/or modify it
85 under the terms of either: the GNU General Public License as published
86 by the Free Software Foundation; or the Artistic License.
87  
88 See L<http://dev.perl.org/licenses/> for more information.
89  
90 =cut
91  
92 5 1;
« Neaf/X/Session/Cookie.pm ↑ Summary Neaf/View.pm »