]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - lib/Variable/Magic.pm
Reference count vmg_op_name_len
[perl/modules/Variable-Magic.git] / lib / Variable / Magic.pm
index b82e214197eeb024a02fb2066aad8ecbbfcb7675..4456efbaa6f11187b9903e7f6102cfac4cef569e 100644 (file)
@@ -13,13 +13,13 @@ Variable::Magic - Associate user-defined magic to variables from Perl.
 
 =head1 VERSION
 
-Version 0.29
+Version 0.30
 
 =cut
 
 our $VERSION;
 BEGIN {
- $VERSION = '0.29';
+ $VERSION = '0.30';
 }
 
 =head1 SYNOPSIS
@@ -53,7 +53,7 @@ It doesn't replace the original semantics : magic callbacks trigger before the o
 
 =item *
 
-It's mostly invisible at the Perl level : magical and non-magical variables cannot be distinguished with C<ref>, C<reftype> or another trick.
+It's mostly invisible at the Perl level : magical and non-magical variables cannot be distinguished with C<ref>, C<tied> or another trick.
 
 =item *
 
@@ -288,19 +288,19 @@ BEGIN {
 
     wizard sig      => ...,
            data     => sub { ... },
-           get      => sub { my ($ref, $data) = @_; ... },
-           set      => sub { my ($ref, $data) = @_; ... },
-           len      => sub { my ($ref, $data, $len) = @_; ... ; return $newlen; },
-           clear    => sub { my ($ref, $data) = @_; ... },
-           free     => sub { my ($ref, $data) = @_, ... },
-           copy     => sub { my ($ref, $data, $key, $elt) = @_; ... },
-           local    => sub { my ($ref, $data) = @_; ... },
-           fetch    => sub { my ($ref, $data, $key) = @_; ... },
-           store    => sub { my ($ref, $data, $key) = @_; ... },
-           exists   => sub { my ($ref, $data, $key) = @_; ... },
-           delete   => sub { my ($ref, $data, $key) = @_; ... },
+           get      => sub { my ($ref, $data [, $op]) = @_; ... },
+           set      => sub { my ($ref, $data [, $op]) = @_; ... },
+           len      => sub { my ($ref, $data, $len [, $op]) = @_; ... ; return $newlen; },
+           clear    => sub { my ($ref, $data [, $op]) = @_; ... },
+           free     => sub { my ($ref, $data [, $op]) = @_, ... },
+           copy     => sub { my ($ref, $data, $key, $elt [, $op]) = @_; ... },
+           local    => sub { my ($ref, $data [, $op]) = @_; ... },
+           fetch    => sub { my ($ref, $data, $key [, $op]) = @_; ... },
+           store    => sub { my ($ref, $data, $key [, $op]) = @_; ... },
+           exists   => sub { my ($ref, $data, $key [, $op]) = @_; ... },
+           delete   => sub { my ($ref, $data, $key [, $op]) = @_; ... },
            copy_key => $bool,
-           op_info  => [ 0 | 1 | 2 ]
+           op_info  => [ 0 | VMG_OP_INFO_NAME | VMG_OP_INFO_OBJECT ]
 
 This function creates a 'wizard', an opaque type that holds the magic information.
 It takes a list of keys / values as argument, whose keys can be :
@@ -423,6 +423,15 @@ If the variable isn't a hash, any C<uvar> callback of the wizard is safely ignor
     my $x;
     die 'error' unless cast $x, $wiz;
 
+The C<var> argument can be an array or hash value.
+Magic for those behaves like for any other scalar, except that it is dispelled when the entry is deleted from the container.
+For example, if you want to call C<POSIX::tzset> each time the C<'TZ'> environment variable is changed in C<%ENV>, you can use :
+
+    use POSIX;
+    cast $ENV{TZ}, wizard set => sub { POSIX::tzset(); () };
+
+If you want to overcome the possible deletion of the C<'TZ'> entry, you have no choice but to rely on C<store> uvar magic.
+
 =head2 C<getdata>
 
     getdata [$@%&*]var, [$wiz|$sig]
@@ -470,8 +479,6 @@ our %EXPORT_TAGS    = (
 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
 
-END { _cleanup() }
-
 =head1 CAVEATS
 
 If you store a magic object in the private data slot, the magic won't be accessible by L</getdata> since it's not copied by assignation.