reftype#
Return the underlying storage type of a reference, ignoring any class it’s been blessed into.
תקציר#
use attributes 'reftype';
my $t = reftype(\@a); # 'ARRAY'
my $t = reftype(bless {}, 'X'); # 'HASH'
מה מוחזר#
One of SCALAR, ARRAY, HASH, CODE, GLOB, IO, FORMAT, LVALUE, or REGEXP. Returns undef when the argument is not a reference.
דוגמאות#
reftype(\1); # 'SCALAR'
reftype([1, 2, 3]); # 'ARRAY'
reftype(sub { }); # 'CODE'
reftype(bless [], 'Foo'); # 'ARRAY' - blessing is ignored
reftype(42); # undef
מקרי קצה#
Not a reference, including
undef: returnsundefrather than croaking.Called with the wrong number of args: croaks with
Usage: attributes::reftype($reference).
הבדלים מן ה-upstream#
Fully compatible with upstream. In upstream attributes.pm this name is a typeglob alias for builtin::reftype; this module provides the same behaviour as a direct XS entry.
ראו גם#
get- usesreftypeto buildFETCH_${type}_ATTRIBUTES._guess_stash- complementary helper for the ”which package?“ half of the same lookup.