NAME

Content - Placeholder class to represent a content of some format and methods to encode and decode between it and a HASH-structure.

SYNOPSIS

my $c=Content::new();

$c->encode();

$c->decode();

DESCRIPTION

A class to define content-formats and methods to encode and decode between them and a HASH-structure. It can handle formats with delimiters or with numbered field sizes. It enables the abstraction of the underlying storage format with the manipulation in Perl of a HASH-structure.

CONSTRUCTOR

new()

Constructor of the class.

It requires no input and the return value is the instance.

METHODS

reset()

Resets the data content of the instance.

The return value is always 1 (success).

set()

Sets the content of the Content-class.

The input must be a pointer to a hash. The return value is 0 upon failure and 1 upon success.

get()

Gets the content of the class.

Returns a pointer to a hash.

encode()

Encodes the content of the class into the format of the Content-class.

It takes no input and the return values are undef upon failure and upon success the encoded data (usually a scalar).

Upon failure the error message can be read by calling the error()-method.

If the delimiter-type of the class in question is a character type (see the delimiter()-method), then the data between the delimiter is to be Base64-encoded.

This class is to be overridden by the inheriting Content-class.

decode()

Decodes the formatted input to the method and puts it into a hash.

It takes the format of the Content-class as input and then return undef upon failure or the remainder of the input if any (scalar). Upon success it sets the content of the Content-class to the hash.

To retrieve the decoded data call the get()-method upon success.

To get the error message after a failure call the error()-method.

If the delimiter-type of the class in question is a character type (see the delimiter()-method), then the data between the delimiter is to be Base64-decoded.

This class is to be overridden by the inheriting Content-class.

type()

Returns the MIME type of the Content-class.

The method takes no input and returns a scalar as the MIME type.

This method is to be overridden by the inheriting Content-class

delimiter()

Return the delimiter of the encoded format of the Content-class

The method takes no input and returns the delimiter in one of the following variants:

The numbers signifies where one field starts, so in the example above the first field starts at the beginning of the encoded data (position 1, not 0) and the next data field after that starts at 6, then after that at 20 and so on.

The next()-method returns fields of data from the encoded data based on this delimiter setting in the Content-class, with the exception of classes where a hash is returned by others libraries directly (more advanced parsing). That is up to the inheriting Content-class to decide. In cases where the delimiter setting is not used, the delimiter shall be blank ("").

This method is to be overridden by the inheriting class to deliver the right delimiter as feedback.

fields()

Returns an array of the field names of the Content-class.

The output will also be an array when getting the field names.

It will always return at least one field name. In cases where the Content is just a converted bulk of data one shall only use one field name. In cases where the content is decoded by a function returning a hash also just set one field name.

Field names should only be set by inheriting Content-class by overriding this class.

resetnext()

Resets he next element iteration of the encoded content of the Content-class. The iteration counter is set to the first element for subsequent calls by the next-method.

The method returns 1 upon success and 0 upon failure.

next()

Gets the next element of the encoded data of the Content-class. The iteration counter is incremented, so that subsequent calls get the next element.

The element is returned based upon the setting of the delimiter-method. If no delimiter is set it will typically just return the whole encoded record.

error()

Gets the last error message from the Content-class.

No input required and the return messages is of type scalar.