SYNOPSIS

  # step 1) you write an input/output driver for a serialized TM format
  package MyFormat;

     # provides methods
     sub deserialize {
         my $self   = shift; # gets current map
         my $stream = shift;
         # .... fill the map with content
     }

     sub serialize {
         my $self = shift; # get the map
         # ....
         return ... #serialized content
     }
  1;

  # step 2) construct a subclass of TM using this driver
  package MapWithMyFormat;

    use TM;
    use base qw(TM);
    use Class::Trait qw(TM::Serializable MyFormat);

    1;

  # step 3) use it in your application
  my $tm = new MapWithMyFormat (url => 'file:map.myformat');
  $tm->sync_in; # uses MyFormat to parse the content from the file

DESCRIPTION

This trait implements synchronizable resources using a serialized format. Examples are formats such as AsTMa 1.0, 2.0, \s-1LTM\s0, \s-1CTM\s0, \s-1XTM\s0. The only thing these drivers have to provide are the methods \*(C`serialize\*(C' and \*(C`deserialize\*(C' which serialize maps to streams and vice-versa.

This trait provides the implementations for \*(C`source_in\*(C' and \*(C`source_out\*(C' triggering \*(C`deserialize\*(C' and \*(C`serialize\*(C', respectively.

INTERFACE

Methods

source_in

Uses the \s-1URL\s0 attached to the map object to trigger \*(C`deserialize\*(C' on the stream content behind the resource. All URLs of \s-1LWP\s0 are supported. If the \s-1URI\s0 is \*(C`io:stdio\*(C' then content from \s-1STDIN\s0 is consumed. This content can be consumed more than once (it is buffered internally), so that you can read several times from \*(C`io:stdin\*(C' getting the same input. If the resource \s-1URI\s0 is \*(C`io:stdout\*(C', then nothing happens. If the resource \s-1URI\s0 is \*(C`null:\*(C', then nothing happens. [Since \s-1TM\s0 1.53]: Any additional parameters are passed through to the underlying \*(C`deserialize\*(C' method.

source_out

This method triggers \*(C`serialize\*(C' on the object. The contents will be copied to the resource identified by the \s-1URI\s0 attached to the object. At the moment, only \*(C`file:\*(C' URLs and \*(C`io:stdout\*(C' is supported. If the resource \s-1URI\s0 is \*(C`io:stdin\*(C', nothing happens. If the resource \s-1URI\s0 is \*(C`null:\*(C', nothing happens. If the resource \s-1URI\s0 is \*(C`inline:..\*(C' nothing happens. [Since \s-1TM\s0 1.53]: Any additional parameters are passed through to the underlying \*(C`serialize\*(C' method.

RELATED TO TM::Serializable…

\s-1TM\s0, TM::Synchronizable

AUTHOR INFORMATION

Copyright 20(0[2-6]|10), Robert Barta <[email protected]>, All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. http://www.perl.com/perl/misc/Artistic.html