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_bytes;

    # Parse frames
    my $frame = Protocol::WebSocket::Frame->new;
    $frame->append(...);
    $f->next; # get next message
    $f->next; # get another next message

DESCRIPTION

Construct or parse a WebSocket frame.

RANDOM MASK GENERATION

By default built-in rand is used, this is not secure, so when Math::Random::Secure is installed it is used instead.

ATTRIBUTES

type

Frame's type. text by default. Other accepted values:

    binary
    ping
    pong
    close

METHODS

new

    Protocol::WebSocket::Frame->new('data');
    Protocol::WebSocket::Frame->new(buffer => 'data', type => 'close');

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

is_text

Check if frame is of text type.

is_binary

Check if frame is of binary type.

is_ping

Check if frame is a ping request.

is_pong

Check if frame is a pong response.

is_close

Check if frame is of close type.

append

    $frame->append(...);

Append a frame chunk.

next

    $frame->append(...);

    $frame->next; # next message

Return the next message as a Perl string.

next_bytes

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

to_bytes

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