package MVC::Neaf::Request::FakeWriter;

use strict;
use warnings;
our $VERSION = '0.28';

=head1 NAME

MVC::Neaf::Request::FakeWriter - part of test suite for Not Even A Framework


See L<MVC::Neaf> and L<MVC::Neaf::Request::PSGI>.
Unless you plan to contribute to framework itself, this module is useless.

This module converts L<PSGI> asynchronous response with callback to a normal
straightforward response ([status, header, content]).


    use Data::Dumper;
    use MVC::Neaf::Request::FakeWriter;

    my $capture = MVC::Neaf::Request::FakeWriter->new;
    my $result = $capture->respond( $psgi_app_return );
    warn Dumper( $result ); # normal PSGI response
        # aka [ status, [ head...], [content...] ]

=head1 METHODS

=head2 new

Constructor (no args).

=head2 respond( sub { ... } )

Respond to provided callback in PSGI-compatible manner.

=head2 write( $data )

Append given data to buffer.

=head2 close()

Do nothing.


sub new {
    return bless {}, shift;

sub respond {
    my ($self, $psgi_ret) = @_;

    return $psgi_ret if ref $psgi_ret eq 'ARRAY';

    $psgi_ret->( sub {
        my $resp = shift;
        $self->{status} = $resp->[0];
        $self->{header} = $resp->[1];
        $self->{content} = $resp->[2] || [];

        return $self;
    } );

    return [ $self->{status}, $self->{header}, $self->{content} ];

sub write {
    my ($self, $data) = @_;
    push @{ $self->{content} }, $data;

sub close {


This module is part of L<MVC::Neaf> suite.

Copyright 2016-2019 Konstantin S. Uvarin C<>.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See L<> for more information.