File: AMF.pm

package info (click to toggle)
libdata-amf-perl 0.09%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 552 kB
  • ctags: 527
  • sloc: perl: 5,955; makefile: 10
file content (119 lines) | stat: -rw-r--r-- 2,222 bytes parent folder | download | duplicates (3)
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
package Data::AMF;
use 5.008001;
use Any::Moose;

our $VERSION = '0.09';

use Data::AMF::Parser;
use Data::AMF::Formatter;

has version => (
    is      => 'rw',
    isa     => 'Int',
    default => sub { 0 },
);

has parser => (
    is      => 'rw',
    lazy    => 1,
    default => sub {
        my $self = shift;
        Data::AMF::Parser->new( version => $self->version );
    },
);

has formatter => (
    is      => 'rw',
    lazy    => 1,
    default => sub {
        my $self = shift;
        Data::AMF::Formatter->new( version => $self->version );
    },
);

no Any::Moose;

sub serialize {
    my $self = shift;
    $self->formatter->format(@_);
}

sub deserialize {
    my $self = shift;
    $self->parser->parse(@_);
}

__PACKAGE__->meta->make_immutable;

__END__

=head1 NAME

Data::AMF - serialize / deserialize AMF data

=head1 SYNOPSIS

    use Data::AMF;
    
    my $amf0 = Data::AMF->new( version => 0 );
    my $amf3 = Data::AMF->new( version => 3 );
    
    # AMF0 to Perl Object
    my $obj = $amf0->deserialize($data);
    
    # Perl Object to AMF0
    my $data = $amf0->serialize($obj);

=head1 DESCRIPTION

This module is (de)serializer for Adobe's AMF (Action Message Format).
Data::AMF is core module and it recognize only AMF data, not AMF packet. If you want to read/write AMF Packet, see Data::AMF::Packet instead.

=head1 SEE ALSO

L<Data::AMF::Packet>, L<Catalyst::Controller::FlashRemoting>

=head1 NOTICE

Data::AMF is currently in a very early alpha development stage.
The current version is not support AMF3, and application interface is still fluid.

=head1 METHOD

=head2 new(%option)

Create Data::AMF object.

Option parameters are:

=over

=item version

Target AMF version.

It should be 0 or 3. (default 0 for AMF0)

=back

=head2 serialize($obj)

Serialize perl object ($obj) to AMF, and return the AMF data.

=head2 deserialize($amf)

Deserialize AMF data to perl object, and return the perl object.

=head1 AUTHOR

Daisuke Murase <typester@cpan.org>

=head1 COPYRIGHT

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut