line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::AMF::Formatter::AMF0; |
2
|
7
|
|
|
7
|
|
41
|
use Any::Moose; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
94
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
require bytes; |
5
|
7
|
|
|
7
|
|
4503
|
use Scalar::Util qw/looks_like_number blessed/; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
795
|
|
6
|
7
|
|
|
7
|
|
43
|
use Data::AMF::IO; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
71
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'io' => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'Data::AMF::IO', |
11
|
|
|
|
|
|
|
lazy => 1, |
12
|
|
|
|
|
|
|
default => sub { |
13
|
|
|
|
|
|
|
Data::AMF::IO->new( data => q[] ); |
14
|
|
|
|
|
|
|
}, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
7
|
|
|
7
|
|
623
|
no Any::Moose; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
41
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub format { |
20
|
0
|
|
|
0
|
1
|
|
my ($self, @obj) = @_; |
21
|
0
|
0
|
|
|
|
|
$self = $self->new unless blessed $self; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
for my $obj (@obj) { |
24
|
0
|
0
|
|
|
|
|
if (my $pkg = blessed $obj) { |
|
|
0
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$self->format_typed_object($obj); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif (my $ref = ref($obj)) { |
28
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->format_strict_array($obj); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($ref eq 'HASH') { |
32
|
0
|
|
|
|
|
|
$self->format_object($obj); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
0
|
|
|
|
|
|
Carp::confess qq[cannot format "$ref" object]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
0
|
0
|
|
|
|
if (looks_like_number($obj) && $obj !~ /^0\d/) { |
|
|
0
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->format_number($obj); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif (defined($obj)) { |
43
|
0
|
|
|
|
|
|
$self->format_string($obj); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
0
|
|
|
|
|
|
$self->format_null($obj); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->io->data; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format_number { |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
56
|
0
|
|
|
|
|
|
$self->io->write_u8(0x00); |
57
|
0
|
|
|
|
|
|
$self->io->write_double($obj); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub format_string { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
62
|
0
|
|
|
|
|
|
$self->io->write_u8(0x02); |
63
|
0
|
|
|
|
|
|
$self->io->write_utf8($obj); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub format_strict_array { |
67
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
68
|
0
|
|
|
|
|
|
my @array = @{ $obj }; |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->io->write_u8(0x0a); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->io->write_u32( scalar @array ); |
73
|
0
|
|
|
|
|
|
for my $v (@array) { |
74
|
0
|
|
|
|
|
|
$self->format($v); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub format_object { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->io->write_u8(0x03); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
for my $key (keys %$obj) { |
84
|
0
|
|
|
|
|
|
my $len = bytes::length($key); |
85
|
0
|
|
|
|
|
|
$self->io->write_u16($len); |
86
|
0
|
|
|
|
|
|
$self->io->write($key); |
87
|
0
|
|
|
|
|
|
$self->format($obj->{$key}); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->io->write_u16(0x00); |
91
|
0
|
|
|
|
|
|
$self->io->write_u8(0x09); # object-end marker |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub format_null { |
95
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->io->write_u8(0x05); # null marker |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub format_typed_object { |
101
|
0
|
|
|
0
|
1
|
|
my ($self, $obj) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->io->write_u8(0x10); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $class = blessed $obj; |
106
|
0
|
|
|
|
|
|
$self->io->write_utf8($class); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->format_object($obj); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |