… | |
… | |
455 | ( |
455 | ( |
456 | sub { Storable::freeze \@_ }, |
456 | sub { Storable::freeze \@_ }, |
457 | sub { @{ Storable::thaw shift } } |
457 | sub { @{ Storable::thaw shift } } |
458 | ) |
458 | ) |
459 | |
459 | |
|
|
460 | =item portable storable - C<$AnyEvent::Fork::RPC::NSTORABLE_SERIALISER> |
|
|
461 | |
|
|
462 | This serialiser also uses L<Storable>, but uses it's "network" format |
|
|
463 | to serialise data, which makes it possible to talk to incompatible |
|
|
464 | perl versions (for example, when talking to a process created with |
|
|
465 | L<AnyEvent::Fork::Remote>). |
|
|
466 | |
|
|
467 | Implementation: |
|
|
468 | |
|
|
469 | use Storable (); |
|
|
470 | ( |
|
|
471 | sub { Storable::nfreeze \@_ }, |
|
|
472 | sub { @{ Storable::thaw shift } } |
|
|
473 | ) |
|
|
474 | |
460 | =back |
475 | =back |
461 | |
476 | |
462 | =back |
477 | =back |
463 | |
478 | |
464 | See the examples section earlier in this document for some actual |
479 | See the examples section earlier in this document for some actual |
465 | examples. |
480 | examples. |
466 | |
481 | |
467 | =cut |
482 | =cut |
468 | |
483 | |
469 | our $STRING_SERIALISER = '(sub { pack "(w/a*)*", @_ }, sub { unpack "(w/a*)*", shift })'; |
484 | our $STRING_SERIALISER = '(sub { pack "(w/a*)*", @_ }, sub { unpack "(w/a*)*", shift })'; |
470 | our $JSON_SERIALISER = 'use JSON (); (sub { JSON::encode_json \@_ }, sub { @{ JSON::decode_json shift } })'; |
485 | our $JSON_SERIALISER = 'use JSON (); (sub { JSON::encode_json \@_ }, sub { @{ JSON::decode_json shift } })'; |
471 | our $STORABLE_SERIALISER = 'use Storable (); (sub { Storable::freeze \@_ }, sub { @{ Storable::thaw shift } })'; |
486 | our $STORABLE_SERIALISER = 'use Storable (); (sub { Storable::freeze \@_ }, sub { @{ Storable::thaw shift } })'; |
|
|
487 | our $NSTORABLE_SERIALISER = 'use Storable (); (sub { Storable::nfreeze \@_ }, sub { @{ Storable::thaw shift } })'; |
472 | |
488 | |
473 | sub run { |
489 | sub run { |
474 | my ($self, $function, %arg) = @_; |
490 | my ($self, $function, %arg) = @_; |
475 | |
491 | |
476 | my $serialiser = delete $arg{serialiser} || $STRING_SERIALISER; |
492 | my $serialiser = delete $arg{serialiser} || $STRING_SERIALISER; |