]> 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 f599b7239861954b5d538368039f6b6c4a960956..991bca17b9339bc0ab1d1a7eeb28ad1475673e10 100644 (file)
@@ -13,13 +13,13 @@ Variable::Magic - Associate user-defined magic to variables from Perl.
 
 =head1 VERSION
 
-Version 0.39
+Version 0.40
 
 =cut
 
 our $VERSION;
 BEGIN {
- $VERSION = '0.39';
+ $VERSION = '0.40';
 }
 
 =head1 SYNOPSIS
@@ -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;
      }
@@ -623,7 +624,7 @@ Tests code coverage report is available at L<http://www.profvince.com/perl/cover
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2007-2009 Vincent Pit, all rights reserved.
+Copyright 2007,2008,2009,2010 Vincent Pit, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.