Magical Functions "Magic" is special data attached to SV structures in order to give them "magical" properties. When any Perl code tries to read from, or assign to, an SV marked as magical, it calls the 'get' or 'set' function associated with that SV's magic. A get is called prior to reading an SV, in order to give it a chance to update its internal value (get on $. writes the line number of the last read filehandle into the SV's IV slot), while set is called after an SV has been written to, in order to allow it to make use of its changed value (set on $/ copies the SV's new value to the PL_rs global variable).
Magic is implemented as a linked list of MAGIC structures attached to the SV. Each MAGIC struct holds the type of the magic, a pointer to an array of functions that implement the get(), set(), length() etc functions, plus space for some flags and pointers. For example, a tied variable has a MAGIC structure that contains a pointer to the object associated with the tie.
Turns on the magical status of an SV. See "sv_magic".
Do magic before a value is retrieved from the SV. The type of SV must be >= SVt_PVMG. See "sv_magic".
Do magic after a value is assigned to the SV. See "sv_magic".
Reports on the SV's length in bytes, calling length magic if available, but does not set the UTF8 flag on sv. It will fall back to 'get' magic if there is no 'length' magic, but with no indication as to whether it called 'get' magic. It assumes sv is a PVMG or higher. Use sv_len() instead.
Clear something magical that the SV represents. See "sv_magic".
Finds the magic pointer for type matching the SV. See "sv_magic".
Finds the magic pointer of type with the given vtbl for the SV. See "sv_magicext".
Copies the magic from one SV to another. See "sv_magic".
Copy some of the magic from an existing SV to new localized version of that SV. Container magic (e.g., %ENV, $1, tie) gets copied, value magic doesn't (e.g., taint, pos).
If setmagic is false then no set magic will be called on the new (empty) SV. This typically means that assignment will soon follow (e.g. 'local $x = $y'), and that will handle the magic.
Free any magic storage used by the SV. See "sv_magic".
Remove any magic of type how from the SV sv. See "sv_magic".
Invoke a magic method (like FETCH).
sv and mg are the tied thingy and the tie magic.
meth is the name of the method to call.
argc is the number of args (in addition to $self) to pass to the method.
The flags can be:
G_DISCARD invoke method with G_DISCARD flag and don't
return a value
G_UNDEF_FILL fill the stack with argc pointers to
PL_sv_undef
The arguments themselves are any values following the flags argument.
Returns the SV (if any) returned by the method, or NULL on failure.
Triggered by a store to %^H, records the key/value pair to PL_compiling.cop_hints_hash. It is assumed that hints aren't storing anything that would need a deep copy. Maybe we should warn if we find a reference.
Triggered by a delete from %^H, records the key to PL_compiling.cop_hints_hash.
Triggered by clearing %^H, resets PL_compiling.cop_hints_hash.