Salvador Fandiño García > Language-Prolog-Types-0.10 > Language::Prolog::Types::Converter

Download:
Language-Prolog-Types-0.10.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Language::Prolog::Types::Converter - Converts from Perl objects to Prolog terms

SYNOPSIS ^

  package MyModule;

  use Language::Prolog::Types::Converter;
  our @ISA=qw(Language::Prolog::Types::Converter);

  sub hash2prolog {
      ...
  }

  sub scalar2prolog {
      ...
  }

  etc.

ABSTRACT ^

This module implements a class to be used from interfaces to Prolog systems (SWI-Prolog, XSB, etc.) to transform complex Perl data types to Prolog types.

DESCRIPTION ^

You should use this module if you want to change the default conversions performed when passing data between Perl and Prolog.

METHODS

Language::Prolog::Types::Converter->new()>

returns a new converter object.

$self->pass_as_opaque($class1, $class2, ...)

instruct the converter object to pass objects belonging to classes class1, class2, etc. to Prolog as opaque objects. The Prolog interpreter will not touch them but just use them in Perl call backs.

To override the default conversions performed, you have to redefine the method perl_ref2prolog.

If you make your converter class inherit Language::Prolog::Types::Converter, you can change conversions only for selected types overriding those methods:

$conv->hash2prolog($hash_ref)

converts a Perl hash reference to a Prolog term.

It creates a list of functors '=>/2' with the key/value pairs as arguments:

  [ '=>'(key0, value0), '=>'(key1, value1), ... ]
$conv->scalar2prolog($scalar_ref)

converts a Perl scalar reference to a Prolog term.

$conv->glob2prolog($glob_ref)

converts a Perl glob reference to a Prolog term.

$conv->code2prolog($code_ref)

converts a Perl sub reference to a Prolog term.

$conv->object2prolog($object_ref)

converts any other Perl object to a Prolog term.

Default implementation looks for a method called convert2prolog_term in the object class.

If this fails, it reverts to dump the internal representation of the object as the functor:

  perl_object(class, state)

state is the conversion of the perl datatype used to represent the object (array, hash, scalar, glob or sub).

EXPORT

None by default. This module has an OO interface.

SEE ALSO ^

Language::Prolog::Types, Language::XSB::Base, Language::Prolog::Yaswi::Low.

AUTHOR ^

Salvador Fandiño, <sfandino@yahoo.com>

COPYRIGHT AND LICENSE ^

Copyright 2002 by Salvador Fandiño

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: