line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Stomp::Frame; |
2
|
11
|
|
|
11
|
|
64
|
use strict; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
257
|
|
3
|
11
|
|
|
11
|
|
64
|
use warnings; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
400
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION='0.60'; |
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
64
|
use base 'Class::Accessor::Fast'; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
4751
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(command headers body)); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
11
|
|
|
11
|
|
38
|
for my $header ( |
12
|
|
|
|
|
|
|
qw(destination exchange content-type content-length message-id reply-to)) |
13
|
|
|
|
|
|
|
{ |
14
|
66
|
|
|
|
|
97
|
my $method = $header; |
15
|
66
|
|
|
|
|
138
|
$method =~ s/-/_/g; |
16
|
11
|
|
|
11
|
|
26388
|
no strict 'refs'; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
755
|
|
17
|
|
|
|
|
|
|
*$method = sub { |
18
|
18
|
|
|
18
|
|
18454
|
my $self = shift; |
19
|
18
|
100
|
|
|
|
160
|
$self->headers->{$header} = shift if @_; |
20
|
18
|
|
|
|
|
339
|
$self->headers->{$header}; |
21
|
66
|
|
|
|
|
5785
|
}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
167
|
|
|
167
|
1
|
26042
|
my $class = shift; |
27
|
167
|
|
|
|
|
528
|
my $self = $class->SUPER::new(@_); |
28
|
167
|
100
|
|
|
|
4242
|
$self->headers({}) unless defined $self->headers; |
29
|
167
|
|
|
|
|
1121
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub as_string { |
33
|
77
|
|
|
77
|
1
|
13383
|
my $self = shift; |
34
|
77
|
|
|
|
|
1160
|
my $command = $self->command; |
35
|
77
|
|
|
|
|
1312
|
my $headers = $self->headers; |
36
|
77
|
|
|
|
|
1276
|
my $body = $self->body; |
37
|
77
|
|
|
|
|
357
|
my $frame = $command . "\n"; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# insert a content-length header |
40
|
77
|
|
|
|
|
111
|
my $bytes_message = 0; |
41
|
77
|
50
|
|
|
|
183
|
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
|
|
|
|
115
|
while ( my ( $key, $value ) = each %{ $headers || {} } ) { |
|
169
|
|
|
|
|
562
|
|
48
|
92
|
50
|
|
|
|
300
|
$frame .= $key . ':' . (defined $value ? $value : '') . "\n"; |
49
|
|
|
|
|
|
|
} |
50
|
77
|
|
|
|
|
138
|
$frame .= "\n"; |
51
|
77
|
|
100
|
|
|
225
|
$frame .= $body || ''; |
52
|
77
|
|
|
|
|
232
|
$frame .= "\0"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub parse { |
56
|
56
|
|
|
56
|
1
|
810
|
my ($class,$string) = @_; |
57
|
|
|
|
|
|
|
|
58
|
56
|
|
|
|
|
261
|
$string =~ s{ |
59
|
|
|
|
|
|
|
\A\s* |
60
|
|
|
|
|
|
|
([A-Z]+)\n #command |
61
|
|
|
|
|
|
|
((?:[^\n]+\n)*)\n # header block |
62
|
|
|
|
|
|
|
}{}smx; |
63
|
56
|
|
|
|
|
174
|
my ($command,$headers_block) = ($1,$2); |
64
|
|
|
|
|
|
|
|
65
|
56
|
100
|
|
|
|
129
|
return unless $command; |
66
|
|
|
|
|
|
|
|
67
|
50
|
|
|
|
|
76
|
my ($headers,$body); |
68
|
50
|
100
|
|
|
|
100
|
if ($headers_block) { |
69
|
49
|
|
|
|
|
138
|
foreach my $line (split(/\n/, $headers_block)) { |
70
|
62
|
|
|
|
|
227
|
my ($key, $value) = split(/\s*:\s*/, $line, 2); |
71
|
62
|
|
|
|
|
183
|
$headers->{$key} = $value; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
50
|
50
|
66
|
|
|
348
|
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
|
|
|
|
140
|
$body = $1 if length($1); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
else { return } # no body |
88
|
|
|
|
|
|
|
|
89
|
50
|
|
|
|
|
219
|
return $class->new({ |
90
|
|
|
|
|
|
|
command => $command, |
91
|
|
|
|
|
|
|
headers => $headers, |
92
|
|
|
|
|
|
|
body => $body, |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |