Author image Marvin Humphrey
and 1 contributors

NAME

Boilerplater::Binding::Perl::TypeMap - Convert between BP and Perl via XS.

DESCRIPTIONS

TypeMap serves up C code fragments for translating between Perl data structures and Boilerplater data structures. The functions to_perl() and from_perl() achieve this for individual types; write_xs_typemap() exports all types using the XS "typemap" format documented in perlxs.

FUNCTIONS

from_perl

    my $c_code = from_perl( $type, $bp_var, $xs_var, $stack_var );

Return C code which converts from a Perl scalar to a variable of type $type.

Variable declarations must precede the returned code, as from_perl() won't make any declarations itself.

  • type - A Boilerplater::Type, which will be used to select the mapping code.

  • bp_var - The name of the variable being assigned to.

  • xs_var - The C name of the Perl scalar from which we are extracting a value.

  • stack_var - Only required needed when type is Boilerplater::Object indicating that bp_var is an object of class CharBuf, ByteBuf, or Obj. When passing strings or other simple types to Boilerplater functions from Perl, we allow the user to supply simple scalars rather than forcing them to create Boilerplater objects. We do this by creating a ZombieCharBuf on the stack and assigning the string from the Perl scalar to it. stack_var is the name of that ZombieCharBuf wrapper.

to_perl

    my $c_code = to_perl( $type, $xs_var, $bp_var );

Return C code which converts from a variable of type $type to a Perl scalar.

Variable declarations must precede the returned code, as to_perl() won't make any declarations itself.

  • type - A Boilerplater::Type, which will be used to select the mapping code.

  • xs_var - The C name of the Perl scalar being assigned to.

  • bp_var - The name of the variable from which we are extracting a value.

CLASS METHODS

write_xs_typemap

    Boilerplater::Binding::Perl::Typemap->write_xs_typemap(
        hierarchy => $hierarchy,
    );

Auto-generate a "typemap" file that adheres to the conventions documented in perlxs.

We generate this file on the fly rather than maintain a static copy because we want an entry for each Boilerplater type so that we can differentiate between them when checking arguments. Keeping the entries up-to-date manually as classes come and go would be a pain.

COPYRIGHT AND LICENSE

Copyright 2008-2009 Marvin Humphrey

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