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.

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.