X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FVariable%2FMagic.pm;h=b82e214197eeb024a02fb2066aad8ecbbfcb7675;hb=b4a1e34ba2c3dc4623d5a399d3c56a84fc14439d;hp=79ca7e9cc7164d945e6a55a24b553db243b9d5e0;hpb=e0b73d014081cd1b04b529deeb606b6459282cfe;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index 79ca7e9..b82e214 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -267,6 +267,14 @@ The perl patchlevel this module was built with, or C<0> for non-debugging perls. True iff this module could have been built with thread-safety features enabled. +=head2 C + +Value to pass with C to get the current op name in the magic callbacks. + +=head2 C + +Value to pass with C to get a C object representing the current op in the magic callbacks. + =head1 FUNCTIONS =cut @@ -291,7 +299,8 @@ BEGIN { store => sub { my ($ref, $data, $key) = @_; ... }, exists => sub { my ($ref, $data, $key) = @_; ... }, delete => sub { my ($ref, $data, $key) = @_; ... }, - copy_key => $bool + copy_key => $bool, + op_info => [ 0 | 1 | 2 ] 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 : @@ -321,6 +330,10 @@ C, C, C, C, C, C, C, C, C Code references to the corresponding magic callbacks. You don't have to specify all of them : the magic associated with undefined entries simply won't be hooked. In those callbacks, C<$_[0]> is always a reference to the magic object and C<$_[1]> is always the private data (or C when no private data constructor was supplied). + +Moreover, when you pass C<< op_info => $num >> to C, the last element of C<@_> will be the current op name if C<$num == VMG_OP_INFO_NAME> and a C object representing the current op if C<$num == VMG_OP_INFO_OBJECT>. +Both have a performance hit, but just getting the name is lighter than getting the op object. + Other arguments are specific to the magic hooked : =over 8 @@ -366,7 +379,7 @@ However, only the return value of the C callback currently holds a meaning. sub wizard { croak 'Wrong number of arguments for wizard()' if @_ % 2; my %opts = @_; - my @keys = qw/sig data get set len clear free/; + my @keys = qw/sig data op_info get set len clear free/; push @keys, 'copy' if MGf_COPY; push @keys, 'dup' if MGf_DUP; push @keys, 'local' if MGf_LOCAL; @@ -446,15 +459,19 @@ use base qw/Exporter/; our @EXPORT = (); our %EXPORT_TAGS = ( 'funcs' => [ qw/wizard gensig getsig cast getdata dispell/ ], - 'consts' => [ qw/SIG_MIN SIG_MAX SIG_NBR MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/, - qw/VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR/, - qw/VMG_COMPAT_SCALAR_LENGTH_NOLEN/, + 'consts' => [ + qw/SIG_MIN SIG_MAX SIG_NBR MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/, + qw/VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR VMG_COMPAT_SCALAR_LENGTH_NOLEN/, qw/VMG_PERL_PATCHLEVEL/, - qw/VMG_THREADSAFE/ ] + qw/VMG_THREADSAFE/, + qw/VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT/ + ] ); 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 since it's not copied by assignation.