X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FVariable%2FMagic.pm;h=9d9e3aecae70339080f5fc4feef463d0d4ca0532;hb=refs%2Ftags%2Fv0.18;hp=f700d74ba66a37ccb278a44b5c5599f4368d1c49;hpb=763ba8093427f3668368fa885741618ac6289d41;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index f700d74..9d9e3ae 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -13,13 +13,13 @@ Variable::Magic - Associate user-defined magic to variables from Perl. =head1 VERSION -Version 0.08 +Version 0.18 =cut our $VERSION; BEGIN { - $VERSION = '0.08'; + $VERSION = '0.18'; } =head1 SYNOPSIS @@ -75,7 +75,7 @@ When this magic is set on a variable, all subsequent localizations of the variab =back -The following actions only applies to hashes and are available iff C is true. They are referred to as C magics. +The following actions only apply to hashes and are available iff C is true. They are referred to as C magics. =over 4 @@ -117,7 +117,7 @@ The places where magic is invoked have changed a bit through perl history. Here' =over 4 -=item 'len' magic is no longer called when pushing an element into a magic array. +=item I : 'len' magic is no longer called when pushing an element into a magic array. =item I : 'local' magic. @@ -133,6 +133,22 @@ The places where magic is invoked have changed a bit through perl history. Here' =back +=head2 B<5.10.0> + +=over 4 + +=item Since C is uppercased, C triggers 'copy' magic on hash stores for (non-tied) hashes that also have 'uvar' magic. + +=back + +=head2 B<5.11.x> + +=over 4 + +=item I : 'len' magic is no longer invoked when calling C with a magical scalar. + +=back + =head1 CONSTANTS =head2 C @@ -163,6 +179,18 @@ Evaluates to true iff the 'local' magic is available. When this constant is true, you can use the C callbacks on hashes. +=head2 C + +True for perls that don't call 'len' magic when you push an element in a magical array. + +=head2 C + +True for perls that call 'clear' magic when undefining magical arrays. + +=head2 C + +True for perls that don't call 'len' magic when taking the C of a magical scalar. + =head1 FUNCTIONS =cut @@ -181,7 +209,7 @@ BEGIN { len => sub { my ($ref, $data, $len) = @_; ... ; return $newlen; }, clear => sub { my ($ref, $data) = @_; ... }, free => sub { my ($ref, $data) = @_, ... }, - copy => sub { my ($ref, $data, $elt) = @_; ... }, + copy => sub { my ($ref, $data, $key, $elt) = @_; ... }, local => sub { my ($ref, $data) = @_; ... }, fetch => sub { my ($ref, $data, $key) = @_; ... }, store => sub { my ($ref, $data, $key) = @_; ... }, @@ -202,7 +230,7 @@ A code reference to a private data constructor. It is called each time this magi =item C, C, C, C, C, C, C, C, C, C and C -Code references to 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). In the special case of C magic and when the variable is an array, C<$_[2]> contains its normal length. C magic receives the current element (i.e. the value) in C<$_[2]>. C<$_[2]> is also the current key in C, C, C and C callbacks. +Code references to 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). In the special case of C magic and when the variable is an array, C<$_[2]> contains its normal length. C<$_[2]> is the current key in C, C, C, C and C callbacks, although for C it may just be a copy of the actual key so it's useless to (for example) cast magic on it. C magic also receives the current element (i.e. the value) in C<$_[3]>. =back @@ -244,7 +272,7 @@ This accessor returns the magic signature of this wizard. cast [$@%&*]var, [$wiz|$sig], ... -This function associates C<$wiz> magic to the variable supplied, without overwriting any other kind of magic. You can also supply the numeric signature C<$sig> instead of C<$wiz>. It returns true on success or when C<$wiz> magic is already present, C<0> on error, and C when no magic corresponds to the given signature (in case C<$sig> was supplied). All extra arguments specified after C<$wiz> are passed to the private data constructor. +This function associates C<$wiz> magic to the variable supplied, without overwriting any other kind of magic. You can also supply the numeric signature C<$sig> instead of C<$wiz>. It returns true on success or when C<$wiz> magic is already present, C<0> on error, and C when no magic corresponds to the given signature (in case C<$sig> was supplied). All extra arguments specified after C<$wiz> are passed to the private data constructor. If the variable isn't a hash, any C callback of the wizard is safely ignored. # Casts $wiz onto $x. If $wiz isn't a signature, undef can't be returned. my $x; @@ -281,11 +309,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/ ] + '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_UNDEF_CLEAR/, + qw/VMG_COMPAT_SCALAR_LENGTH_NOLEN/ ] ); our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; $EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; +=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. The only way to address this would be to return a reference. + +If you define a wizard with a C callback and cast it on itself, this destructor won't be called because the wizard will be destroyed first. + =head1 DEPENDENCIES L 5.7.3. @@ -306,17 +342,13 @@ L and L for other ways of enhancing objects. =head1 AUTHOR -Vincent Pit, C<< >> +Vincent Pit, C<< >>, L. -You can contact me by mail or on #perl @ FreeNode (Prof_Vince). +You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince). =head1 BUGS -Please report any bugs or feature requests to -C, or through the web interface at -L. -I will be notified, and then you'll automatically be notified of progress on -your bug as I make changes. +Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT @@ -324,6 +356,8 @@ You can find documentation for this module with the perldoc command. perldoc Variable::Magic +Tests code coverage report is available at L. + =head1 COPYRIGHT & LICENSE Copyright 2007-2008 Vincent Pit, all rights reserved.