Tag 26 Data Item array [classname, constructargs...] Semantics Serialised Perl object with classname and constructor arguments Reference http://cbor.schmorp.de/perl-object Contact Marc A. Lehmann <cbor@schmorp.de>
The perl-object tag in CBOR can be used to serialise Perl 5 objects into CBOR.
The tagged value must be a CBOR array with at least one element. The first element specifies a classname to use in Perl (it can, but does not need to be a string - the stringified form will be used as classname).
The encoder and decoder should serialise/deserialise the object using the Types::Serialiser object serialisation protocol. For this, the object's class must have FREEZE and THAW methods that are called like this:
@constructargs = $object->FREEZE ("CBOR"); $object = $class->THAW ("CBOR", @constructargs);
If the class or method is currently not available, the decoder may try to load a Perl module of the same name and retry the method call.
Example of a hypothetical My::DateTime representation using a unix timestamp:
26(["My::DateTime", 12345678]) d8 1a # tag(26) 82 # array(2) 6c # text(12) 4d793a3a4461746554696d65 # "My::DateTime" 1a 00bc614e # unsigned(12345678)
Example of the corresponding FREEZE method:
sub My::DateTime::FREEZE { my ($self, $model) = @_; $self->as_seconds }
Example of the corresponding THAW method:
sub My::DateTime::THAW { my ($class, $model, $seconds) = @_; $class->new_from_seconds ($seconds) }
This section lists known implementations of this extension (drop me a mail if you want to be listed here).