getdata#
שליפת הנתונים הפרטיים שהצירוף של ה־wizard הזה נושא.
תקציר#
use Peta::XS ':magic';
my $data = getdata(\$x, $w); # whatever $w's data callback returned
מה מוחזר#
הנתונים הפרטיים של הצירוף - הערך שה־callback של data של ה־wizard החזיר בזמן cast - או undef כאשר ל־wizard הזה אין צירוף על המשתנה או שאין ל־wizard callback של data. זהו אותו ערך שה־callbacks של get/set/free מקבלים כארגומנט השני שלהם: אם הוא הפניה, שינויים שנעשים בתוך callbacks נראים כאן.
דוגמאות#
# per-variable access statistics, read back after the fact
my $counted = wizard(
data => sub { { reads => 0, writes => 0 } },
get => sub { $_[1]{reads}++ },
set => sub { $_[1]{writes}++ },
);
my $x = 1;
cast(\$x, $counted);
my $v = $x; $v = $x; # two reads
$x = 2; # one write
my $stats = getdata(\$x, $counted);
say "$stats->{reads}/$stats->{writes}"; # 2/1
# distinguishing "no attachment" from "no data"
say defined getdata(\$x, $counted) ? 'attached' : 'not here';