line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::AMF::IO; |
2
|
7
|
|
|
7
|
|
51
|
use Any::Moose; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
66
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
require bytes; |
5
|
|
|
|
|
|
|
|
6
|
7
|
50
|
|
7
|
|
3801
|
use constant ENDIAN => unpack('S', pack('C2', 0, 1)) == 1 ? 'BIG' : 'LITTLE'; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
1233
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has data => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'Str', |
11
|
|
|
|
|
|
|
default => sub { '' }, |
12
|
|
|
|
|
|
|
lazy => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has pos => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'Int', |
18
|
|
|
|
|
|
|
default => sub { 0 }, |
19
|
|
|
|
|
|
|
lazy => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has refs => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'ArrayRef', |
25
|
|
|
|
|
|
|
default => sub { [] }, |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
7
|
|
39
|
no Any::Moose; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
40
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub read { |
32
|
177
|
|
|
177
|
1
|
235
|
my ($self, $len) = @_; |
33
|
|
|
|
|
|
|
|
34
|
177
|
100
|
|
|
|
749
|
if ($len + $self->pos > bytes::length($self->data) ) { |
35
|
24
|
|
|
|
|
111
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
153
|
|
|
|
|
4562
|
my $data = substr $self->data, $self->pos, $len; |
39
|
153
|
|
|
|
|
443
|
$self->pos( $self->pos + $len ); |
40
|
|
|
|
|
|
|
|
41
|
153
|
|
|
|
|
377
|
$data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub read_u8 { |
45
|
150
|
|
|
150
|
1
|
179
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
150
|
|
|
|
|
284
|
my $data = $self->read(1); |
48
|
150
|
100
|
|
|
|
389
|
return unless defined $data; |
49
|
|
|
|
|
|
|
|
50
|
126
|
|
|
|
|
506
|
unpack('C', $data); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub read_u16 { |
54
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
my $data = $self->read(2); |
57
|
0
|
0
|
|
|
|
0
|
return unless defined $data; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
unpack('n', $data); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub read_s16 { |
63
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my $data = $self->read(2); |
66
|
0
|
0
|
|
|
|
0
|
return unless defined $data; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
0
|
return unpack('s>', $data) if $] >= 5.009002; |
69
|
0
|
|
|
|
|
0
|
return unpack('s', $data) if ENDIAN eq 'BIG'; |
70
|
0
|
|
|
|
|
0
|
return unpack('s', swap($data)); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub read_u24 { |
74
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
my $data = $self->read(3); |
77
|
0
|
|
|
|
|
0
|
return unpack('N', "\0$data"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub read_u32 { |
81
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
my $data = $self->read(4); |
84
|
0
|
|
|
|
|
0
|
unpack('N', $data); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub read_double { |
88
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
5
|
|
|
|
|
15
|
my $data = $self->read(8); |
91
|
|
|
|
|
|
|
|
92
|
5
|
50
|
|
|
|
55
|
return unpack('d>', $data) if $] >= 5.009002; |
93
|
0
|
|
|
|
|
0
|
return unpack('d', $data) if ENDIAN eq 'BIG'; |
94
|
0
|
|
|
|
|
0
|
return unpack('d', swap($data)); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub read_utf8 { |
98
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my $len = $self->read_u16; |
101
|
0
|
0
|
|
|
|
0
|
return unless defined $len; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
$self->read($len); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub read_utf8_long { |
107
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
my $len = $self->read_u32; |
110
|
0
|
0
|
|
|
|
0
|
return unless defined $len; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
$self->read($len); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub swap { |
116
|
0
|
|
|
0
|
1
|
0
|
join '', reverse split '', $_[0]; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub write { |
120
|
93
|
|
|
93
|
1
|
131
|
my ($self, $data) = @_; |
121
|
93
|
|
|
|
|
307
|
$self->{data} .= $data; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub write_u8 { |
125
|
77
|
|
|
77
|
1
|
92
|
my ($self, $data) = @_; |
126
|
77
|
|
|
|
|
235
|
$self->write( pack('C', $data) ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub write_u16 { |
130
|
0
|
|
|
0
|
1
|
0
|
my ($self, $data) = @_; |
131
|
0
|
|
|
|
|
0
|
$self->write( pack('n', $data) ); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub write_s16 { |
135
|
0
|
|
|
0
|
1
|
0
|
my ($self, $data) = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
0
|
return $self->write( pack('s>', $data) ) if $] >= 5.009002; |
138
|
0
|
|
|
|
|
0
|
return $self->write( pack('s', $data) ) if ENDIAN eq 'BIG'; |
139
|
0
|
|
|
|
|
0
|
return $self->write( swap pack('s', $data) ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub write_u24 { |
143
|
0
|
|
|
0
|
1
|
0
|
my ($self, $data) = @_; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
$data = pack('N', $data); |
146
|
0
|
|
|
|
|
0
|
$data = substr $data, 1, 3; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
0
|
$self->write($data); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub write_u32 { |
152
|
0
|
|
|
0
|
1
|
0
|
my ($self, $data) = @_; |
153
|
0
|
|
|
|
|
0
|
$self->write( pack('N', $data) ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub write_double { |
157
|
2
|
|
|
2
|
1
|
5
|
my ($self, $data) = @_; |
158
|
|
|
|
|
|
|
|
159
|
2
|
50
|
|
|
|
16
|
return $self->write( pack('d>', $data) ) if $] >= 5.009002; |
160
|
0
|
|
|
|
|
|
return $self->write( pack('d', $data) ) if ENDIAN eq 'BIG'; |
161
|
0
|
|
|
|
|
|
return $self->write( swap pack('d', $data) ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub write_utf8 { |
165
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $len = bytes::length($data); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$self->write_u16($len); |
170
|
0
|
|
|
|
|
|
$self->write($data); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub write_utf8_long { |
174
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my $len = bytes::length($data); |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
$self->write_u32($len); |
179
|
0
|
|
|
|
|
|
$self->write($data); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |