XS::Framework::Manual::SVAPI::Glob - XS::Framework Glob C++ class reference
The Glob class is the wrapper around Perls GV* type, which is a variant of SV*. As with Scalar, it might hold an underlying Perl SV* or might not.
Glob
GV*
SV*
Scalar
The Glob object does not holds undef; if undef is assigned or supplied in constructor, the object is considered empty. In other words the undef and NULL have the same meaning for the class.
undef
NULL
A GV is a structure which corresponds to a Perl typeglob, ie *foo. It is a structure that holds a pointer to a scalar, an array, a hash etc, corresponding to $foo, @foo, %foo.
GV
*foo
$foo
@foo
%foo
GVs are usually found as values in stashes (symbol table hashes) where Perl stores its global variables.
GVs
To create a new GV* in Perl, the Stash object and the name should be provided:
Stash
static Glob create (const Stash& stash, panda::string_view name, U32 flags = 0);
For the flags description please refer gv_init_pvn in perlapi.
flags
gv_init_pvn
To create an wrapper around existing GV* the following constructors can be used:
Glob (std::nullptr_t = nullptr) Glob (SV* sv, bool policy = INCREMENT) Glob (GV* sv, bool policy = INCREMENT)
If SV* or <GV*> are undef or NULL, the returned Glob object will be empty. Otherwise, if unappropriate SV* is supplied, then exception will be thrown.
Copy and move-constructore are also available:
Glob (const Glob& oth) Glob (Glob&& oth) Glob (const Scalar& oth) Glob (Scalar&& oth) Glob (const Sv& oth) Glob (Sv&& oth)
Glob& operator= (SV* val) Glob& operator= (GV* val) Glob& operator= (const Glob& oth) Glob& operator= (Glob&& oth) Glob& operator= (const Scalar& oth) Glob& operator= (Scalar&& oth) Glob& operator= (const Sv& oth) Glob& operator= (Sv&& oth)
The assignment operators are complementaty to the constructors above. They inherit behaviour from Scalar, including NULL-safety. The previously held SV* will be dec-remented.
dec
The last operator performs proxy call in scalar context, the same as in appropriate constructor above.
void set (SV* val) void set (GV* val)
The set method directly assigns the value to the underlying SV*, bypassing all checks. Use the method with caution.
set
Theere are zero-cost NULL-safe getters:
operator GV* () const GV* operator->() const template <typename T = SV> one_of_t<T,SV,GV>* get () const
This are NULL-safe methods. The returned value, however, might be NULL.
template <typename T> one_of_t<T,Scalar,Array,Hash,Sub> slot () const void slot (SV*) void slot (AV*) void slot (HV*) void slot (CV*) void slot (IO*) void slot (const Scalar&) void slot (const Sv& v) void slot (const Array& v) void slot (const Hash& v) void slot (const Sub& v) void slot (const Io& v)
This are read/write accessors for appropriate slot type in the Glob instance. For example:
Stash s = ...; Glob o = s["some_name"]; Sub sub = o.slot<Sub>();
The slot methods are NULL-unsafe.
slot
Scalar scalar () const Array array () const Hash hash () const Sub sub () const Io io () const void scalar (const Scalar& val) void array (const Array& val) void hash (const Hash& val) void sub (const Sub& val) void io (const Io& val)
This group of methods provide convenient access to scalar/array/hash/sub/io slot of the Glob. The read accessors are NULL-safe, while write-accessors are NULL-unsafe.
Sv get_const () const
If Sub-slot is eligible for inlining it returns the valuer returned by the Sub wrapped into Sv. Otherwise emptu Sv is returned.
Sub
Sv
This is NULL-unsafe method.
Stash stash () const Stash effective_stash () const
Returns the current or effective Stash associated with the Glob instance.
This are NULL-unsafe methods.
panda::string_view name () const panda::string_view effective_name () const
Returns the name of the current or effective Stash associated with the Glob instance.
XS::Framework
XS::Framework::Manual::SVAPI
XS::Framework::Manual::SVAPI::Scalar
XS::Framework::Manual::SVAPI::Stash
To install XS::Framework, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XS::Framework
CPAN shell
perl -MCPAN -e shell install XS::Framework
For more information on module installation, please visit the detailed CPAN module installation guide.