Name : perl-Variable-Magic
| |
Version : 0.64
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp154.1.1
| Date : 2024-03-22 20:31:51
|
Group : Unspecified
| Source RPM : perl-Variable-Magic-0.64-lp154.1.1.src.rpm
|
Size : 0.13 MB
| |
Packager : https://www_suse_com/
| |
Summary : Associate user-defined magic to variables from Perl
|
Description :
Magic is Perl\'s way of enhancing variables. This mechanism lets the user add extra data to any variable and hook syntactical operations (such as access, assignment or destruction) that can be applied to it. With this module, you can add your own magic to any variable without having to write a single line of XS.
You\'ll realize that these magic variables look a lot like tied variables. It is not surprising, as tied variables are implemented as a special kind of magic, just like any \'irregular\' Perl variable : scalars like \'$!\', \'$(\' or \'$^W\', the \'%ENV\' and \'%SIG\' hashes, the \'AATTISA\' array, \'vec()\' and \'substr()\' lvalues, threads::shared variables... They all share the same underlying C API, and this module gives you direct access to it.
Still, the magic made available by this module differs from tieing and overloading in several ways :
* Magic is not copied on assignment.
You attach it to variables, not values (as for blessed references).
* Magic does not replace the original semantics.
Magic callbacks usually get triggered before the original action takes place, and cannot prevent it from happening. This also makes catching individual events easier than with \'tie\', where you have to provide fallbacks methods for all actions by usually inheriting from the correct \'Tie::Std*\' class and overriding individual methods in your own class.
* Magic is multivalued.
You can safely apply different kinds of magics to the same variable, and each of them will be invoked successively.
* Magic is type-agnostic.
The same magic can be applied on scalars, arrays, hashes, subs or globs. But the same hook (see below for a list) may trigger differently depending on the type of the variable.
* Magic is invisible at Perl level.
Magical and non-magical variables cannot be distinguished with \'ref\', \'tied\' or another trick.
* Magic is notably faster.
Mainly because perl\'s way of handling magic is lighter by nature, and because there is no need for any method resolution. Also, since you don\'t have to reimplement all the variable semantics, you only pay for what you actually use.
The operations that can be overloaded are :
* _get_
This magic is invoked when the variable is evaluated. It is never called for arrays and hashes.
* _set_
This magic is called each time the value of the variable changes. It is called for array subscripts and slices, but never for hashes.
* _len_
This magic only applies to arrays (though it used to also apply to scalars), and is triggered when the \'size\' or the \'length\' of the variable has to be known by Perl. This is typically the magic involved when an array is evaluated in scalar context, but also on array assignment and loops (\'for\', \'map\' or \'grep\'). The length is returned from the callback as an integer.
Starting from perl 5.12, this magic is no longer called by the \'length\' keyword, and starting from perl 5.17.4 it is also no longer called for scalars in any situation, making this magic only meaningful on arrays. You can use the constants VMG_COMPAT_SCALAR_LENGTH_NOLEN and VMG_COMPAT_SCALAR_NOLEN to see if this magic is available for scalars or not.
* _clear_
This magic is invoked when the variable is reset, such as when an array is emptied. Please note that this is different from undefining the variable, even though the magic is called when the clearing is a result of the undefine (e.g. for an array, but actually a bug prevent it to work before perl 5.9.5 - see the history).
* _free_
This magic is called when a variable is destroyed as the result of going out of scope (but not when it is undefined). It behaves roughly like Perl object destructors (i.e. \'DESTROY\' methods), except that exceptions thrown from inside a _free_ callback will always be propagated to the surrounding code.
* _copy_
When applied to tied arrays and hashes, this magic fires when you try to access or change their elements.
Starting from perl 5.17.0, it can also be applied to closure prototypes, in which case the magic will be called when the prototype is cloned. The VMG_COMPAT_CODE_COPY_CLONE constant is true when your perl support this feature.
* _dup_
This magic is invoked when the variable is cloned across threads. It is currently not available.
* _local_
When this magic is set on a variable, all subsequent localizations of the variable will trigger the callback. It is available on your perl if and only if \'MGf_LOCAL\' is true.
The following actions only apply to hashes and are available if and only if VMG_UVAR is true. They are referred to as _uvar_ magics.
* _fetch_
This magic is invoked each time an element is fetched from the hash.
* _store_
This one is called when an element is stored into the hash.
* _exists_
This magic fires when a key is tested for existence in the hash.
* _delete_
This magic is triggered when a key is deleted in the hash, regardless of whether the key actually exists in it.
You can refer to the tests to have more insight of where the different magics are invoked.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-V/15.4/x86_64 |