++ed by:
6 non-PAUSE users
Author image Marvin Humphrey
and 1 contributors


Clownfish::CFC::Binding::Perl - Perl bindings for a Clownfish::CFC::Hierarchy.


Clownfish::CFC::Binding::Perl presents an interface for auto-generating XS and Perl code to bind C code for a Clownfish class hierarchy to Perl.

In theory this module could be much more flexible and its API could be more elegant. There are many ways which you could walk the parsed parcels, classes, methods, etc. in a Clownfish::CFC::Hierarchy and generate binding code. However, our needs are very limited, so we are content with a "one size fits one" solution.

In particular, this module assumes that the XS bindings for all classes in the hierarchy should be assembled into a single shared object which belongs to the primary, "boot" class. There's no reason why it could not write one .xs file per class, or one per parcel, instead.

The files written by this class are derived from the name of the boot class. If it is "Crustacean", the following files will be generated.

    # Generated by write_bindings()

    # Generated by write_boot()



    my $perl_binding = Clownfish::CFC::Binding::Perl->new(
        boot_class => 'Crustacean',                    # required
        parcel     => 'Crustacean',                    # required
        hierarchy  => $hierarchy,                      # required
        lib_dir    => 'lib',                           # required
        header     => "/* Autogenerated file */\n",    # required
        footer     => $copyfoot,                       # required
  • boot_class - The name of the main class, which will own the shared object.

  • parcel - The Clownfish::CFC::Parcel to which the boot_class belongs.

  • hierarchy - A Clownfish::CFC::Hierarchy.

  • lib_dir - location of the Perl lib directory to which files will be written.

  • header - Text which will be prepended to generated C/XS files -- typically, an "autogenerated file" warning.

  • footer - Text to be appended to the end of generated C/XS files -- typically copyright information.



Generate the XS bindings (including "Autobind.pm) for all classes in the hierarchy.


    my $filepaths_and_pod = $perl_binding->prepare_pod;
    while ( my ( $filepath, $pod ) = each %$filepaths_and_pod ) {
        spew_file( $filepath, $pod );

Auto-generate POD for all classes bindings which were spec'd with make_pod directives. See whether a .pod file exists and is up to date.

Return a hash representing POD files that need to be modified; the keys are filepaths, and the values are the POD file content.

The caller must take responsibility for actually writing out the POD files, after adding the filepaths to cleanup records and so on.



Write out "boot" files to the Hierarchy's dest_dir which contain code for bootstrapping Clownfish classes.