line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Stomp::Frame; |
2
|
11
|
|
|
11
|
|
38
|
use strict; |
|
11
|
|
|
|
|
10
|
|
|
11
|
|
|
|
|
247
|
|
3
|
11
|
|
|
11
|
|
34
|
use warnings; |
|
11
|
|
|
|
|
9
|
|
|
11
|
|
|
|
|
336
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION='0.57'; |
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
34
|
use base 'Class::Accessor::Fast'; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
4840
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(command headers body)); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
11
|
|
|
11
|
|
20
|
for my $header ( |
12
|
|
|
|
|
|
|
qw(destination exchange content-type content-length message-id reply-to)) |
13
|
|
|
|
|
|
|
{ |
14
|
66
|
|
|
|
|
63
|
my $method = $header; |
15
|
66
|
|
|
|
|
99
|
$method =~ s/-/_/g; |
16
|
11
|
|
|
11
|
|
23195
|
no strict 'refs'; |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
716
|
|
17
|
|
|
|
|
|
|
*$method = sub { |
18
|
18
|
|
|
18
|
|
12656
|
my $self = shift; |
19
|
18
|
100
|
|
|
|
54
|
$self->headers->{$header} = shift if @_; |
20
|
18
|
|
|
|
|
56
|
$self->headers->{$header}; |
21
|
66
|
|
|
|
|
4340
|
}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
167
|
|
|
167
|
1
|
9469
|
my $class = shift; |
27
|
167
|
|
|
|
|
383
|
my $self = $class->SUPER::new(@_); |
28
|
167
|
100
|
|
|
|
1156
|
$self->headers({}) unless defined $self->headers; |
29
|
167
|
|
|
|
|
785
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub as_string { |
33
|
77
|
|
|
77
|
1
|
8854
|
my $self = shift; |
34
|
77
|
|
|
|
|
121
|
my $command = $self->command; |
35
|
77
|
|
|
|
|
230
|
my $headers = $self->headers; |
36
|
77
|
|
|
|
|
212
|
my $body = $self->body; |
37
|
77
|
|
|
|
|
192
|
my $frame = $command . "\n"; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# insert a content-length header |
40
|
77
|
|
|
|
|
68
|
my $bytes_message = 0; |
41
|
77
|
50
|
|
|
|
142
|
if ( $headers->{bytes_message} ) { |
42
|
0
|
|
|
|
|
0
|
$bytes_message = 1; |
43
|
0
|
|
|
|
|
0
|
delete $headers->{bytes_message}; |
44
|
0
|
|
|
|
|
0
|
$headers->{"content-length"} = length( $self->body ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
77
|
50
|
|
|
|
61
|
while ( my ( $key, $value ) = each %{ $headers || {} } ) { |
|
169
|
|
|
|
|
474
|
|
48
|
92
|
50
|
|
|
|
205
|
$frame .= $key . ':' . (defined $value ? $value : '') . "\n"; |
49
|
|
|
|
|
|
|
} |
50
|
77
|
|
|
|
|
75
|
$frame .= "\n"; |
51
|
77
|
|
100
|
|
|
184
|
$frame .= $body || ''; |
52
|
77
|
|
|
|
|
162
|
$frame .= "\0"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub parse { |
56
|
56
|
|
|
56
|
1
|
464
|
my ($class,$string) = @_; |
57
|
|
|
|
|
|
|
|
58
|
56
|
|
|
|
|
266
|
$string =~ s{ |
59
|
|
|
|
|
|
|
\A\s* |
60
|
|
|
|
|
|
|
([A-Z]+)\n #command |
61
|
|
|
|
|
|
|
((?:[^\n]+\n)*)\n # header block |
62
|
|
|
|
|
|
|
}{}smx; |
63
|
56
|
|
|
|
|
119
|
my ($command,$headers_block) = ($1,$2); |
64
|
|
|
|
|
|
|
|
65
|
56
|
100
|
|
|
|
93
|
return unless $command; |
66
|
|
|
|
|
|
|
|
67
|
50
|
|
|
|
|
48
|
my ($headers,$body); |
68
|
50
|
100
|
|
|
|
68
|
if ($headers_block) { |
69
|
49
|
|
|
|
|
106
|
foreach my $line (split(/\n/, $headers_block)) { |
70
|
62
|
|
|
|
|
196
|
my ($key, $value) = split(/\s*:\s*/, $line, 2); |
71
|
62
|
|
|
|
|
138
|
$headers->{$key} = $value; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
50
|
50
|
66
|
|
|
246
|
if ($headers && $headers->{'content-length'}) { |
|
|
50
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
if (length($string) >= $headers->{'content-length'}) { |
77
|
|
|
|
|
|
|
$body = substr($string, |
78
|
|
|
|
|
|
|
0, |
79
|
0
|
|
|
|
|
0
|
$headers->{'content-length'}, |
80
|
|
|
|
|
|
|
'' ); |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
0
|
else { return } # not enough body |
83
|
|
|
|
|
|
|
} elsif ($string =~ s/\A(.*?)\0//s) { |
84
|
|
|
|
|
|
|
# No content-length header. |
85
|
50
|
100
|
|
|
|
120
|
$body = $1 if length($1); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
else { return } # no body |
88
|
|
|
|
|
|
|
|
89
|
50
|
|
|
|
|
150
|
return $class->new({ |
90
|
|
|
|
|
|
|
command => $command, |
91
|
|
|
|
|
|
|
headers => $headers, |
92
|
|
|
|
|
|
|
body => $body, |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |