The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Protocol::WebSocket::Frame - WebSocket Frame

SYNOPSIS

    # Create frame
    my $frame = Protocol::WebSocket::Frame->new('123');
    $frame->to_string; # \x00123\xff

    # Parse frames
    my $frame = Protocol::WebSocket::Frame->new;
    $frame->append("123\x00foo\xff56\x00bar\xff789");
    $f->next; # foo
    $f->next; # bar

DESCRIPTION

Construct or parse a WebSocket frame.

METHODS

new

Create a new Protocol::WebSocket::Frame instance. Automatically detect if the passed data is a Perl string or bytes.

append

    $frame->append("\x00foo");
    $frame->append("bar\xff");

Append a frame chunk.

next

    $frame->append("\x00foo");
    $frame->append("\xff\x00bar\xff");

    $frame->next; # foo
    $frame->next; # bar

Return the next frame as a Perl string.

next_bytes

Return the next frame as a UTF-8 encoded string.

to_string

    my $frame = Protocol::WebSocket::Frame->new('foo');
    $frame->to_string; # \x00foo\xff

Construct a WebSocket frame as a Perl string.

to_bytes

Construct a WebSocket frame as a UTF-8 encoded string.