03 Oct 2022 16:44:37 UTC
- Distribution: XS-Framework
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (106 / 2 / 19)
- KwaliteeBus factor: 3
- License: unknown
- Perl: v5.22.0
- Download (174.14KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
XS::Framework::Manual::Cookbook - XS::Framework cookbook / tutorial
The cookbook consists of recipes, showing the XS::Framework how mechanics works, and, most imporant part, the problems which might be encounted in adopting C++ into perl and how to overcome them.
All sources are availalbe in
t/cookbook. Please, use the recipes with the reference ( XS::Framework::Manual::Typemap ), where concepts are disclosed.
XS::Framework::Manual::recipe01 demonstrates how to adopt the very simple C++ class; it expains
XS::Framework::Manual::recipe02 demonstrates another difference between
ObjectStorageMGstorage policies from Perl inheritance and extendability point of view.
XS::Framework::Manual::recipe03 demonstrates how to use
ObjectTypeForeignPtrlifetime policy for C++ objects which follows Singleton pattern with
ObjectStorageIV, also it inroduces the notion of const typemap.
XS::Framework::Manual::recipe04 demonstrates how to use
ObjectTypeSharedPtrlifetime policy when C++ API returns std::shared_ptr.
XS::Framework::Manual::recipe05 demonstrates how to use
ObjectTypeRefcntPtrlifetime policy for C++ API classes with ref-counter support.
XS::Framework::Manual::recipe06 demonstrates how to map C++ classes hierarchy to hierarchy of typemaps and hierarhy of xs-adapters.
XS::Framework::Manual::recipe07 shows what is C3-inheritance in Perl, and how to achive the same in xs-adepters using XS::Framework. The underlying unrelated C++ classes are used to provide basic functions.
XS::Framework::Manual::recipe08 demonstrates how to bind unrelated, but similar C++ classes into single Perl class hierarchy.
If underlying C++ class does not gives enough flexibility for Perl developer, the XS::Framework::Manual::recipe09 shows how to use payload magic or inheritance to store additional runtime association between C++ objects and arbitrary perl data.
There might be cases when C++ offers API for it's objects, where lifetime of one object is linked to the lifetime of the other, i.e. it is returned as reference. In Perl script their lifetimes might be different, as it should be never assumed how Perl developer will use Perl objects. XS::Framework::Manual::recipe10 shows how to "decouple" xs-adapter lifetimes using magic payload.
If you have control on C++ classes, the XS::Framework::Manual::recipe11 expains that providing shared ownership on the object is the most friendly way to integrate them into Perl, and probably other scripting languages. The
std::shared_ptrand intrusive refcounter approach are explained.
It is not safe to directly port transient C++ classes, i.e. very short living objects which exist only quant of time. The XS::Framework::Manual::recipe12 shows how to make them non-transient and, that way, safe by the cost of copying dependent C++ objects.
In the XS::Framework::Manual::recipe13 it is shown how to maintain Perl objects data and class identity when they are moved into native C++ containers and returned back; the Backrefs capabilities of XS::Framework should be used.
Module Install Instructions
To install XS::Framework, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install XS::Framework
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|