]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - lib/Variable/Magic.pm
Tune the userdata example
[perl/modules/Variable-Magic.git] / lib / Variable / Magic.pm
index 04ed9df8fcd2556237d4d74ac5694390918969cc..991bca17b9339bc0ab1d1a7eeb28ad1475673e10 100644 (file)
@@ -417,7 +417,8 @@ Value to pass with C<op_info> to get a C<B::OP> object representing the current
 
 =head2 Associate an object to any perl variable
 
-This can be useful for passing user data through limited APIs.
+This technique can be useful for passing user data through limited APIs.
+It is similar to using inside-out objects, but without the drawback of having to implement a complex destructor.
 
     {
      package Magical::UserData;
@@ -430,9 +431,9 @@ This can be useful for passing user data through limited APIs.
       my ($var) = @_;
       my $data = &getdata($var, $wiz);
       unless (defined $data) {
-       &cast($var, $wiz);
-       $data = &getdata($var, $wiz);
-       die "Couldn't cast UserData magic onto the variable" unless defined $data;
+       $data = \(my $slot);
+       &cast($var, $wiz, $slot)
+                        or die "Couldn't cast UserData magic onto the variable";
       }
       $$data;
      }