-
-
22 Jun 2022 12:35:59 UTC
- Distribution: Export-XS
- Module version: 3.0.6
- Source (raw)
- Pod Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues
- Testers (148 / 0 / 0)
- Kwalitee
Bus factor: 3- License: unknown
- Activity
24 month- Tools
- Download (6.48KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- XS::Framework
- XS::Install
- XS::libpanda
- next::XS
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- SYNOPSIS
- C SYNOPSIS
- DESCRIPTION
- C FUNCTIONS
-
-
- void create_constant (Stash stash, string_view name, const Sv& value)
- void create_constant (Stash stash, string_view name, string_view value)
- void create_constant (Stash stash, string_view name, int64_t value)
- void create_constant (Stash stash, const Constant& constant)
- void create_constants (Stash stash, const std::initializer_list<Constant>& constants)
- void create_constants (Stash stash, const Hash& constants)
- void create_constants (Stash stash, SV*const* list, size_t items)
- void autoexport (Stash stash)
- void export_sub (const Stash& from, Stash to, string_view name)
- void export_constants (const Stash& from, Stash to)
- void register_export (const Stash& stash, string_view name)
- Array constants_list (const Stash& stash)
-
-
- PERFOMANCE
- AUTHOR
- LICENSE
NAME
Export::XS - Replacement for Exporter.pm + const.pm in XS, with C++ API.
SYNOPSIS
Exporting functions
package MyModule; use Export::XS::Auto; sub mysub { ... } sub mysub2 { ... } 1; package Somewhere; use MyModule qw/mysub mysub2/; mysub();
Creating and using constants (without export)
package MyModule; use Export::XS CONST1 => 1, CONST2 => 'string'; say CONST1; say CONST2;
Creating and using constants with export
package MyModule; use Export::XS::Auto { CONST1 => 1, CONST2 => 'string', }; say CONST1; say CONST2; package Somewhere; use MyModule; say CONST1; say CONST2;
C SYNOPSIS
#include <xs/export.h> using namespace xs::exp; // one-by-one create_constant(stash, "STATUS_OFF", 0); create_constant(stash, "STATUS_ACTIVE", 1); create_constant(stash, "STATUS_SUSPENDED", 2); create_constant(stash, "STATUS_PENDING", 3); create_constant(stash, "DEFAULT_NAME", "john"); create_constant(stash, "CONST_NAME", value_sv); autoexport(stash); // bulk create_constants(stash, { {"STATUS_OFF", 0}, {"STATUS_ACTIVE", 1}, {"STATUS_SUSPENDED", 2}, {"STATUS_PENDING", 3}, {"DEFAULT_NAME", "john"} }); // exporting subs export_sub(from_stash, to_stash, "myfunc"); // export all constants export_constants(from, to);
DESCRIPTION
It's very fast not only in runtime but at compile time as well. That means you can create and export/import a lot of constants/functions without slowing down the startup.
You can create constants by saying
use Export::XS {CONST_NAME1 => VALUE1, ...}; use Export::XS CONST_NAME1 => VALUE1, ... ;
If you want your class to able to export constants or functions, use
Export::XS::Auto
instead ofExport::XS
.Exports specified constants and functions to caller's package.
use MyModule qw/subs list/;
Exports nothing
use MyModule();
Exports all constants only (no functions)
use MyModule;
Exports functions sub1 and sub2 and all constants
use MyModule qw/sub1 sub2 :const/;
If Export::XS discovers name collision while creating or exporting functions or constants it raises an exception. If you specify wrong sub or const name in import list an exception will also be raisen.
C FUNCTIONS
API is thread-safe.
Sv
,Stash
, and so on is SVAPI classes (Perl C++ API), see XS::Framework.string_view
is apanda::string_view
which is implementation of C++17's string_view, see XS::libpanda.struct Constant { Constant (string_view name, const Sv& val); Constant (string_view name, string_view val); Constant (string_view name, int64_t val); };
void create_constant (Stash stash, string_view name, const Sv& value)
void create_constant (Stash stash, string_view name, string_view value)
void create_constant (Stash stash, string_view name, int64_t value)
Creates constant with name
name
and valuevalue
in packagestash
. Croaks if package already has sub/constant with that name.void create_constant (Stash stash, const Constant& constant)
Creates constant with name
constant.name
and value <constant.value> instash
.void create_constants (Stash stash, const std::initializer_list<Constant>& constants)
Creates a constant for each element in
constants
.void create_constants (Stash stash, const Hash& constants)
Creates a constant for each key/value pair in
constants
.void create_constants (Stash stash, SV*const* list, size_t items)
Creates a constant for each key/value pair in array
list
. It means that list[0] is a key, list[1] is a value, list[2] is a key, etc... Array should not contain empty slots and empty keys or it will croak. If elements count is odd, last element is ignored. You must pass the size oflist
initems
.void autoexport (Stash stash)
Makes
stash
autoexport its constants when someone saysuse ThatClass; # ThatClass is stash.name()
void export_sub (const Stash& from, Stash to, string_view name)
Exports sub/constant with name
name
from packagefrom
to package <to>.void export_constants (const Stash& from, Stash to)
Exports all constants from package
from
to package <to>.void register_export (const Stash& stash, string_view name)
Forces an export of a function with specified name by default (along with constants), i.e. when user says
use SomeClass;
Array constants_list (const Stash& stash)
Returns the list of all constants defined in package
stash
as a perl array.PERFOMANCE
Export::XS is up to 10x faster than const.pm and Exporter.pm at compile-time. The runtime perfomance is the same as it doesn't depend on this module.
AUTHOR
Pronin Oleg <syber@cpan.org>, Crazy Panda LTD
LICENSE
You may distribute this code under the same terms as Perl itself.
Module Install Instructions
To install Export::XS, copy and paste the appropriate command in to your terminal.
cpanm Export::XS
perl -MCPAN -e shell install Export::XS
For more information on module installation, please visit the detailed CPAN module installation guide.