Apache2::REST::Writer::yaml_stream - Apache2::REST::Response Writer for streaming yaml


Apache2-REST documentation Contained in the Apache2-REST distribution.

Index


Code Index:

NAME

Top

Apache2::REST::Writer::yaml_stream - Apache2::REST::Response Writer for streaming yaml

new

mimeType

Getter

getPreambleBytes

Returns the response preamble - nothing interesting here

getPreambleBytes

Returns the response postamble - nothing interesting here

getNextBytes

Returns the next chunk of data as yaml bytes


Apache2-REST documentation Contained in the Apache2-REST distribution.
package Apache2::REST::Writer::yaml_stream;
use strict ;

use YAML;
use Data::Dumper ;

use base qw/Apache2::REST::WriterStream/;

sub new{
    my ( $class ) = @_;
    return bless {} , $class;
}

sub mimeType{
    return 'text/yaml';
}

sub getPreambleBytes{
    return Encode::encode_utf8("") ;
}


sub getPostambleBytes{
    my ($self, $resp) = @_;
    ## Just close the response.
    return Encode::encode_utf8("");
}

sub getNextBytes {
    my ($self,  $resp) = @_;
    my $nextChunk = $resp->stream->nextChunk();
    unless( defined $nextChunk ){ return undef;}
    unless( ref $nextChunk ){
        confess($resp->stream()."->nextChunk MUST return a chunk of data as a reference, not a binary string");
    }
    # shallow unblessed copy
    my %resp = %$nextChunk;
    my $yaml = Dump(\%resp) ;
    ## yaml is a perl string, not bytes.
    return Encode::encode_utf8($yaml) ;
}

1;