Storable::AMF3 - serializing/deserializing AMF3 data


Storable-AMF documentation Contained in the Storable-AMF distribution.

Index


Code Index:

NAME

Top

Storable::AMF3 - serializing/deserializing AMF3 data

SYNOPSIS

Top

  use Storable::AMF3 qw(freeze thaw); 

  $amf3 = freeze($perl_object);
  $perl_object = thaw($amf3);

	


  # Store/retrieve to disk amf3 data

  store $perl_object, 'file';
  $restored_perl_object = retrieve 'file';




  use Storable::AMF3 qw(nstore freeze thaw dclone);

  


  # Advisory locking
  use Storable::AMF3 qw(lock_store lock_nstore lock_retrieve)
  lock_store \%table, 'file';
  lock_nstore \%table, 'file';
  $hashref = lock_retrieve('file');

  # Deparse one object
  use Storable::AMF0 qw(deparse_amf); 

  my( $obj, $length_of_packet ) = deparse_amf( my $bytea = freeze($a1) . freeze($a) ... );

  - or -
  $obj = deparse_amf( freeze($a1) . freeze($a) ... );

DESCRIPTION

Top

This module is (de)serializer for Adobe's AMF3 (Action Message Format ver 3). This is only module and it recognize only AMF3 data. Almost all function implemented in C for speed. And some cases faster then Storable( for me always)

EXPORT

Top

  None by default.

FUNCTIONS =cut

Top

freeze($obj) --- Serialize perl object($obj) to AMF3, and return AMF data
thaw($amf3) --- Deserialize AMF data to perl object, and return the perl object
store $obj, $file --- Store serialized AMF3 data to file
nstore $obj, $file --- Same as store
retrieve $obj, $file --- Retrieve serialized AMF3 data from file
lock_store $obj, $file --- Same as store but with Advisory locking
lock_nstore $obj, $file --- Same as lock_store
lock_retrieve $file --- Same as retrieve but with advisory locking
dclone $file --- Deep cloning data structure
ref_clear $obj --- cleaning arrayref and hashref. (Usefull for destroing complex objects)
ref_lost_memory $obj --- test if object contain lost memory fragments inside. (Example do { my $a = []; @$a=$a; $a})
deparse_amf $bytea --- deparse from bytea one item Return one object and number of bytes readed if scalar context return object
parse_option =item parse_serializator_option generate option scalar for freeze/thaw/deparse_amf See Storable::AMF0 for complete list of options

LIMITATION

Top

At current moment and with restriction of AMF0/AMF3 format referrences to scalar are not serialized, and can't/ may not serialize tied variables.

SEE ALSO

Top

Data::AMF, Storable, Storable::AMF3, Storable::AMF

AUTHOR

Top

Anatoliy Grishaev, <grian at cpan dot org>

THANKS

Top

	Alberto Reggiori. ( basic externalized object support )
	Adam Lounds.      ( tests and some ideas and code for boolean support )

COPYRIGHT AND LICENSE

Top


Storable-AMF documentation Contained in the Storable-AMF distribution.
package Storable::AMF3;
use strict;
use warnings;
use Fcntl qw(:flock);
use subs qw(freeze thaw);
use Exporter 'import';
use Carp qw(croak);
BEGIN{
	our $VERSION;
	$VERSION='1.00' unless $INC{'Storable/AMF0.pm'};
};
use Storable::AMF0 ();

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

our %EXPORT_TAGS = (
    'all' => [
        qw(
          freeze thaw	dclone retrieve lock_retrieve lock_store lock_nstore store nstore
          ref_clear ref_lost_memory
          deparse_amf new_amfdate perl_date
		  new_date
		  parse_option
		  parse_serializator_option
          )
    ]
);

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw();

sub retrieve($) {
    my $file = shift;
    my $lock = shift;

    open my $fh, "<:raw", $file or croak "Can't open file \"$file\" for read.";
    flock $fh, LOCK_SH if $lock;
    my $buf;
    sysread $fh, $buf, (( sysseek $fh, 0, 2 ), sysseek $fh, 0,0)[0] ;
    return thaw($buf);
}

sub lock_retrieve($) {
    $_[1] = 1;
    goto &retrieve;
}

sub store($$) {
    my ( $object, $file, $lock ) = @_;

    my $freeze = \freeze($object);
    unless (defined $$freeze ){
        croak "Bad object";
    }
    else  {
	open my $fh, ">:raw", $file or croak "Can't open file \"$file\" for write.";
        flock $fh, LOCK_EX if $lock;
        print $fh $$freeze if defined $$freeze;
    };
}

sub lock_store($$) {
    $_[2] = 1;
    goto &store;
}
{{
    no warnings 'once';
    *nstore = \&store;
    *lock_nstore = \&lock_store;
}};
1;
__END__
# Below is stub documentation for your module. You'd better edit it!