=head1 NAME XS::Framework::Manual::SVAPI::Stash - XS::Framework Stash C++ class reference =head1 Stash =head2 Overview The C class extension of C class, which provides convenient access to perl symbol table as well as symbol resolution via C, C and C methods. Stash may be empty, i.e. contain C C. =head2 Construction static Stash root () Returns Perl's default stash. Stash (std::nullptr_t = nullptr) Creates an empty stash. static Stash from_name (SV* fqn, I32 flags = 0) Stash (const panda::string_view& package, I32 flags = 0) Looks up for the specified fully-qualified package name and returns, may be empty, C object for the result. The C are additional parameters for lookup, e.g. C will create new symbol table. See C in L. Stash (SV* sv, bool policy = INCREMENT) Stash (HV* sv, bool policy = INCREMENT) Upgrades hash C, which already refers to symbol table, or reference to it (C) into object. If the supplied agrument is invalid, the exception will be thrown. It is possible that the first agrument be C or C, in that case empty stash will be crated. Copy and move-constructore are also available: Stash (const Stash& oth) Stash (const Hash& oth) Stash (const Sv& oth) Stash (Stash&& oth) Stash (Hash&& oth) Stash (Sv&& oth) =head2 assignment operators Stash& operator= (SV* val) Stash& operator= (HV* val) Stash& operator= (const Stash& oth) Stash& operator= (Stash&& oth) Stash& operator= (const Hash& oth) Stash& operator= (Hash&& oth) Stash& operator= (const Sv& oth) Stash& operator= (Sv&& oth) The assignment operators are complementaty to the constructors above. They inherit behaviour from C, including NULL-safety. The previously held C will be C-remented. void set (HV* val) The C method directly assigns the value to the underlying C in the form of C, I. Use the method with caution. =head2 element access Glob fetch (const panda::string_view& key) Glob at (const panda::string_view& key) Glob operator[] (const panda::string_view& key) op_proxy operator[] (const panda::string_view& key) The first three methods return C type via the C string. C provides safe access to the elements, i.e. in case of absence of a key empty C will be returned. The C method will throw error of the specified C is not found in the current symbol table. The C is the alias for C method. The non-const C allows in-place fast modification of underlying element, i.e. Stash stash = Stash("my::package", GV_ADD); stash["PI"] = Simple(3.14); All the methods above are NULL-safe; the assingment of empty stash leads to thrown exception. void store (const panda::string_view& key, SV* v) void store (const panda::string_view& key, AV* v) void store (const panda::string_view& key, HV* v) void store (const panda::string_view& key, CV* v) void store (const panda::string_view& key, GV* v) void store (const panda::string_view& key, IO* v) void store (const panda::string_view& key, const Sv& v) void store (const panda::string_view& key, const Scalar& v) void store (const panda::string_view& key, const Array& v) void store (const panda::string_view& key, const Hash& v) void store (const panda::string_view& key, const Sub& v) void store (const panda::string_view& key, const Glob& v) void store (const panda::string_view& key, const Io& v) The NULL-safe C method allows to inject the new value into the stash. The exception will be thrown if the stash object is empty. The following methods provide convenient access C symbol values, when the type is known: Scalar scalar (const panda::string_view& name) const Array array (const panda::string_view& name) const Hash hash (const panda::string_view& name) const Sub sub (const panda::string_view& name) const Io io (const panda::string_view& name) const void scalar (const panda::string_view& name, const Scalar& v) void array (const panda::string_view& name, const Array& v) void hash (const panda::string_view& name, const Hash& v) void sub (const panda::string_view& name, const Sub& v) void io (const panda::string_view& name, const Io& v) The read-access is NULL-safe; the write-access (i.e assignment) on empty C throws exception. Usage example: Stash stash = Stash("my::package"); auto pi = stash.scalar("pi"); stash.scalar("e", Simple(2.71)); // will throw if "my::package" is not known to Perl =head2 method access Sub method (const Sv& name) const Sub method (const panda::string_view& name) const Sub method_strict (const Sv& name) const Sub method_strict (const panda::string_view& name) const Sub super_method (const Sub& current) const Sub super_method_strict (const Sub& current) const Sub next_method (const Sub& current) const Sub next_method_strict (const Sub& current) const The method resolving can be performed either via C or C name. If a method name cannot be found, the empty C is returned. To avoid that the C should be invoked; if the method C cannot be found, then exception will be thrown. The C takes the existing C and tries to find the corresponding method in the B package of the current C. It uses the resolution order specified in the class (i.e. C). The C tries to find the next method using method resolution order, see L. The C<_strict> version throw exception if nothing is found. This are null-unsafe methods. Usage example: Stash stash = Stash("my::derived"); Sub m_child = stash.method("method"); Sub m_parent = stash.super_method(m_child); m_parent.call(); =head2 method call *depends* call (const Sv& name, Args&&...args) const *depends* call (const panda::string_view& name, Args&&...args) const *depends* call_SUPER (const Sub& context, Args&&...args) const *depends* call_next (const Sub& context, Args&&...args) const *depends* call_next_maybe (const Sub& context, Args&&...args) const *depends* call_super (const Sub& context, Args&&...args) const *depends* call_super_maybe (const Sub& context, Args&&...args) const It is possible to invoke arbitrary method with arbitrary arguments if method C is known in a C; if method is not found, then an exception will be thrown. The C / C / C will lookup for corresponding method in the parent or next class in the hierachy (see L). The diffence between C / C is how the parent method is looked-up: either via classical DFS MRO resolution or via class-defined resolution (i.e. C3 if 'use mro c3' or DFS otherwise). The same methods with C<_maybe> prefix do exist: if the corresponding metthod is not found, then empty result will be returned, i.e. no exception will be thrown. This are null-unsafe methods. =head2 package name panda::string_view name () const HEK* name_hek () const const Simple& name_sv () const To know the name of the package, to which the current C object points, the C, C and C methods can be used. For example: Stash stash = Stash("my::package"); auto name = stash.name(); // returns "my::package" If it is planned to let the package name be used in Perl in future, then prefer to use C method. panda::string_view effective_name () const It is possible to have I of the current stash, if the stash was aliased. See C in L. This are null-unsafe methods. =head2 path() panda::string path () const Returns the file path for the current stash, i.e. Stash s("A::B::C", GV_ADD); s.path(); // returns A/B/C.pm =head2 mark_as_loaded() void mark_as_loaded (const Stash& source) const void mark_as_loaded (const panda::string_view& source) const Let the perl knows, where the current C comes from, i.e. inserts into the perl C variable the C for the current C. This is useful, when writing multiple XS-bases packages in a single module. L ships with a few useful macros, so, it is usually used in the C section of the package like the following: Stash(__PACKAGE__, GV_ADD).mark_as_loaded(__MODULE__); The typical sympthom to use C is the following error: Can't locate MyModule/MyClass.pm in @INC =head2 inherit() void inherit (const Stash& parent) void inherit (const panda::string_view& parent) Links the current symbol table as the descendant class for C C. In other words, it the following construct: Stash child("MyPackage::Child"); // or, better Stash(__PACKAGE__, GV_ADD) child.mark_as_loaded(__MODULE__); Stash base("MyPackage::Base"); child.inherit(base); is equivalent to perl code: package MyPackage::Child; use parent qw/MyPackage::Base/; If the C package is defined as C, it will be automatically added to Perl via C. The C is NULL-safe method; the exception will be thrown if it is invoked on empty C. =head2 isa() bool isa (const panda::string_view& parent, U32 hash = 0, int flags = 0) const bool isa (HEK* hek) const bool isa (const Stash& parent) const The C method returns C if the current C exactly matches C C or if the current C is child class for the C C. The similar code in Perl is child_CLASS->isa(parent_CLASS); Under the hood the method uses C function (see C). =head2 bless() Object bless () const; This method creates new C, which is blessed into to the current package (C). Object bless (const Sv& what) const; This C method version works somewhat similiar to the following Perl construction my $class = ...; my $obj = ...; return bless $obj => $class; i.e. if C is already an object, it is blessed into the C, otherwise new C created from the C argument, and the blessed object returned. =head2 add_const_sub() void add_const_sub (const panda::string_view& name, const Sv& val); Creates subroutine C that returns constant C eligible for compile-time inlining (like newCONSTSUB). C is retained and made readonly. C can be either any C or . In latter case, const sub will return list containing array's values. =head1 SEE ALSO L L L L =cut