/usr/share/perl5/Net/Stomp/Frame.pm is in libnet-stomp-perl 0.56-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | package Net::Stomp::Frame;
use strict;
use warnings;
our $VERSION='0.56';
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw(command headers body));
BEGIN {
for my $header (
qw(destination exchange content-type content-length message-id reply-to))
{
my $method = $header;
$method =~ s/-/_/g;
no strict 'refs';
*$method = sub {
my $self = shift;
$self->headers->{$header} = shift if @_;
$self->headers->{$header};
};
}
}
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->headers({}) unless defined $self->headers;
return $self;
}
sub as_string {
my $self = shift;
my $command = $self->command;
my $headers = $self->headers;
my $body = $self->body;
my $frame = $command . "\n";
# insert a content-length header
my $bytes_message = 0;
if ( $headers->{bytes_message} ) {
$bytes_message = 1;
delete $headers->{bytes_message};
$headers->{"content-length"} = length( $self->body );
}
while ( my ( $key, $value ) = each %{ $headers || {} } ) {
$frame .= $key . ':' . (defined $value ? $value : '') . "\n";
}
$frame .= "\n";
$frame .= $body || '';
$frame .= "\0";
}
sub parse {
my ($class,$string) = @_;
$string =~ s{
\A\s*
([A-Z]+)\n #command
((?:[^\n]+\n)*)\n # header block
}{}smx;
my ($command,$headers_block) = ($1,$2);
return unless $command;
my ($headers,$body);
if ($headers_block) {
foreach my $line (split(/\n/, $headers_block)) {
my ($key, $value) = split(/\s*:\s*/, $line, 2);
$headers->{$key} = $value;
}
}
if ($headers && $headers->{'content-length'}) {
if (length($string) >= $headers->{'content-length'}) {
$body = substr($string,
0,
$headers->{'content-length'},
'' );
}
else { return } # not enough body
} elsif ($string =~ s/\A(.*?)\0//s) {
# No content-length header.
$body = $1 if length($1);
}
else { return } # no body
return $class->new({
command => $command,
headers => $headers,
body => $body,
});
}
1;
__END__
=head1 NAME
Net::Stomp::Frame - A STOMP Frame
=head1 SYNOPSIS
use Net::Stomp::Frame;
my $frame = Net::Stomp::Frame->new( {
command => $command,
headers => $headers,
body => $body,
} );
my $frame = Net::Stomp::Frame->parse($string);
my $string = $frame->as_string;
=head1 DESCRIPTION
This module encapulates a Stomp frame.
A Stomp frame consists of a command, a series of headers and a body.
For details on the protocol see L<https://stomp.github.io/>.
=head1 METHODS
=head2 new
Create a new L<Net::Stomp::Frame> object:
my $frame = Net::Stomp::Frame->new( {
command => $command,
headers => $headers,
body => $body,
} );
=head2 parse
Create a new L<Net::Somp::Frame> given a string containing the serialised frame:
my $frame = Net::Stomp::Frame->parse($string);
=head2 as_string
Create a string containing the serialised frame representing the frame:
my $string = $frame->as_string;
=head2 command
Get or set the frame command.
=head2 body
Get or set the frame body.
=head2 headers
Get or set the frame headers, as a hashref. All following methods are
just shortcuts into this hashref.
=head2 destination
Get or set the C<destination> header.
=head2 content_type
Get or set the C<content-type> header.
=head2 content_length
Get or set the C<content-length> header.
=head2 exchange
Get or set the C<exchange> header.
=head2 message_id
Get or set the C<message-id> header.
=head2 reply_to
Get or set the C<reply-to> header.
=head1 SEE ALSO
L<Net::Stomp>.
=head1 AUTHOR
Leon Brocard <acme@astray.com>.
=head1 CONTRIBUTORS
Gianni Ceccarelli <dakkar@thenautilus.net>
=head1 COPYRIGHT
Copyright (C) 2006, Leon Brocard
This module is free software; you can redistribute it or modify it
under the same terms as Perl itself.
|