From: Vincent Pit Date: Tue, 23 Jun 2009 23:47:14 +0000 (+0200) Subject: Make getdata() return an empty list when no magic is present X-Git-Tag: v0.36~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=544f8a0bb4359368c34abd3f7c7f9dfc83a3f7f5;p=perl%2Fmodules%2FVariable-Magic.git Make getdata() return an empty list when no magic is present And correct the wrong chunk of doc that had slipped in when the wizard validation cleanup happened. --- diff --git a/Magic.xs b/Magic.xs index 13ffad0..77b6209 100644 --- a/Magic.xs +++ b/Magic.xs @@ -1468,7 +1468,7 @@ PPCODE: sig = vmg_wizard_sig(wiz); data = vmg_data_get(SvRV(sv), sig); if (!data) - XSRETURN_UNDEF; + XSRETURN_EMPTY; ST(0) = data; XSRETURN(1); diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index 44edfe6..2ca4012 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -401,7 +401,7 @@ Of course, this example does nothing with the values that are added after the C< getdata [$@%&*]var, [$wiz|$sig] This accessor fetches the private data associated with the magic C<$wiz> (or the signature C<$sig>) in the variable. -It croaks when C<$wiz> or C<$sig> do not represent a current valid magic object attached to the variable, and returns C when the wizard has no data constructor or when the data is actually C. +It croaks when C<$wiz> or C<$sig> do not represent a valid magic object, and returns an empty list if no such magic is attached to the variable or when the wizard has no data constructor. # Get the attached data, or undef if the wizard does not attach any. my $data = getdata $x, $wiz; diff --git a/t/13-data.t b/t/13-data.t index a67b79c..41e0b3a 100644 --- a/t/13-data.t +++ b/t/13-data.t @@ -78,9 +78,9 @@ $res = eval { cast $a, $wiz }; is($@, '', 'cast non-data wizard doesn\'t croak'); ok($res, 'cast non-data wizard returns true'); -$data = eval { getdata $a, $wiz }; -is($@, '', 'getdata from non-data wizard doesn\'t croak'); -is($data, undef, 'getdata from non-data wizard invalid returns undef'); +my @data = eval { getdata $a, $wiz }; +is($@, '', 'getdata from non-data wizard doesn\'t croak'); +is_deeply(\@data, [ ], 'getdata from non-data wizard invalid returns undef'); $wiz = wizard data => sub { ++$_[1] }; my ($di, $ei) = (1, 10);