The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::Content - Content

SYNOPSIS

    use Mojo::Content;

    my $content = Mojo::Content->new;
    $content->parse("Content-Length: 12\r\n\r\nHello World!");

DESCRIPTION

Mojo::Content is a container for HTTP content.

ATTRIBUTES

Mojo::Content inherits all attributes from Mojo::Stateful and implements the following new ones.

body_cb

    my $cb = $content->body_cb;

    $counter = 1;
    $content = $content->body_cb(sub {
        my $self  = shift;
        my $chunk = '';
        $chunk    = "hello world!" if $counter == 1;
        $chunk    = "hello world2!\n\n" if $counter == 2;
        $counter++;
        return $chunk;
    });

body_length

    my $body_length = $content->body_length;

buffer

    my $buffer = $content->buffer;
    $content   = $content->buffer(Mojo::Buffer->new);

builder_progress_cb

    my $cb   = $content->builder_progress_cb;
    $content = $content->builder_progress_cb(sub {
        my $self = shift;
        print '+';
    });

file

    my $file = $content->file;
    $content = $content->file(Mojo::File::Memory->new);

filter_buffer

    my $filter_buffer = $content->filter_buffer;
    $content          = $content->filter_buffer(Mojo::Buffer->new);

header_length

    my $header_length = $content->header_length;

headers

    my $headers = $content->headers;
    $content    = $content->headers(Mojo::Headers->new);

raw_header_length

    my $raw_header_length = $content->raw_header_length;

raw_body_length

    my $raw_body_length = $content->raw_body_length;

METHODS

Mojo::Content inherits all methods from Mojo::Stateful and implements the following new ones.

build_body

    my $string = $content->build_body;

build_headers

    my $string = $content->build_headers;

body_contains

    my $found = $content->body_contains;

get_body_chunk

    my $chunk = $content->get_body_chunk(0);

get_header_chunk

    my $chunk = $content->get_header_chunk(13);

is_chunked

    my $chunked = $content->is_chunked;

is_multipart

    my $multipart = $content->is_multipart;

parse

    $content = $content->parse("Content-Length: 12\r\n\r\nHello World!");