Magic "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"
.
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".
Remove any magic of type how
using virtual table vtbl
from the SV sv
. See "sv_magic".
mg_freeext(sv, how, NULL)
is equivalent to mg_free_type(sv, how)
.
Generates the message string describing an OS error and returns it as an SV. errnum
must be a value that errno
could take, identifying the type of error.
If tgtsv
is non-null then the string will be written into that SV (overwriting existing content) and it will be returned. If tgtsv
is a null pointer then the string will be written into a new mortal SV which will be returned.
The message will be taken from whatever locale would be used by $!
, and will be encoded in the SV in whatever manner would be used by $!
. The details of this process are subject to future change. Currently, the message is taken from the C locale by default (usually producing an English message), and from the currently selected locale when in the scope of the use locale
pragma. A heuristic attempt is made to decode the message from the locale's character encoding, but it will only be decoded as either UTF-8 or ISO-8859-1. It is always correctly decoded in a UTF-8 locale, usually in an ISO-8859-1 locale, and never in any other locale.
The SV is always returned containing an actual string, and with no other OK bits set. Unlike $!
, a message is even yielded for errnum
zero (meaning success), and if no useful message is available then a useless string (currently empty) is returned.
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.
These all convert a signal name into its corresponding signal number; returning -1 if no corresponding number was found.
They differ only in the source of the signal name:
whichsig_pv
takes the name from the NUL
-terminated string starting at sig
.
whichsig
is merely a different spelling, a synonym, of whichsig_pv
.
whichsig_pvn
takes the name from the string starting at sig
, with length len
bytes.
whichsig_sv
takes the name from the PV stored in the SV sigsv
.
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
.