]> git.vpit.fr Git - perl/modules/Variable-Magic.git/commitdiff
Importing Variable-Magic-0.02.tar.gz v0.02
authorVincent Pit <vince@profvince.com>
Sun, 29 Jun 2008 16:24:18 +0000 (18:24 +0200)
committerVincent Pit <vince@profvince.com>
Sun, 29 Jun 2008 16:24:18 +0000 (18:24 +0200)
Changes
MANIFEST
META.yml
Magic.xs
README
lib/Variable/Magic.pm
t/31-array.t
t/32-hash.t
t/34-glob.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 1cf4720e4112cf25105d2d21bf50527ae026a932..bcd60be04f25c56f628770e6b00c436dee9459f4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,14 @@
 Revision history for Variable-Magic
 
+0.02    2007-07-27 13:50 UTC
+        + Fix : In response to test report 548152 :
+                Newx() and SvMAGIC_set() not present on older perls.
+        + Fix : In response to test report 548275 :
+                Since perl 5.9.5, 'clear' magic is invoked when an array is
+                undefined (bug #43357). Moreover, 'len' magic is no longer
+                called by pushing an element since perl 5.9.3.
+        + Fix : Missing glob test in MANIFEST.
+
 0.01    2007-07-25 16:15 UTC
         First version, released on an unsuspecting world.
 
index 5c2edd7729f418954e655e22a55a5511613ae6d8..f07ba3e58efdb19e0b9c4f30ecdbad6f7283a9af 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -20,6 +20,7 @@ t/30-scalar.t
 t/31-array.t
 t/32-hash.t
 t/33-code.t
+t/34-glob.t
 t/boilerplate.t
 t/kwalitee.t
 t/pod-coverage.t
index cb4d04614c23317431f6fd4f94a34899801fe916..afc6683d0607d129b77bb9908f3627399cfdd255 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Variable-Magic
-version:             0.01
+version:             0.02
 abstract:            Associate user-defined magic to variables from Perl.
 license:             perl
 generated_by:        ExtUtils::MakeMaker version 6.36
index 2f6db15714aef875fce91a292695c0a647b024a4..be5e8f8f234f7c3dc0bb9bee1b7a7a59456856d6 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -3,6 +3,16 @@
 #include "perl.h"
 #include "XSUB.h"
 
+/* --- Compatibility ------------------------------------------------------- */
+
+#ifndef Newx
+# define Newx(v, n, c) New(0, v, n, c)
+#endif
+
+#ifndef SvMAGIC_set
+# define SvMAGIC_set(sv, val) (SvMAGIC(sv) = (val))
+#endif
+
 #define SIG_WIZ ((U16) (1u << 8 - 1))
 
 #define R(S) fprintf(stderr, "R(" #S ") = %d\n", SvREFCNT(sv))
diff --git a/README b/README
index 541b09da0daa68af9a14683aa6da0137ba1b4c0f..c7ce74e74b0d17778f74680589850b5e3cf879bc 100644 (file)
--- a/README
+++ b/README
@@ -2,7 +2,7 @@ NAME
     Variable::Magic - Associate user-defined magic to variables from Perl.
 
 VERSION
-    Version 0.01
+    Version 0.02
 
 SYNOPSIS
         use Variable::Magic qw/wizard cast dispell/;
@@ -41,8 +41,9 @@ DESCRIPTION
     "clear"
         This magic is invoked when the variable is reset, such as when an
         array is emptied. Please note that this is different from undefining
-        the variable, even though the magic is called when the reset is a
-        result of the undefine (e.g. for an array).
+        the variable, even though the magic is called when the clearing is a
+        result of the undefine (e.g. for an array, but actually a bug
+        prevent it to work before perl 5.9.5 - see the history).
 
     "free"
         This last one can be considered as an object destructor. It happens
@@ -53,6 +54,15 @@ DESCRIPTION
     an unique numerical signature is attached to each kind of magic (i.e.
     each set of callbacks for magic operations).
 
+PERL MAGIC HISTORY
+  5.9.3
+    'len' magic is no longer called when pushing an element into a magic
+    array.
+
+  5.9.5
+    'clear' magic wasn't invoked when undefining an array. The bug is fixed
+    as of this version.
+
 CONSTANTS
   "SIG_MIN"
     The minimum integer used as a signature for user-defined magic.
index 9944a9102df012175232d687346082c53b88a9de..07fa6f53d786dcf9852f8c48244d1f0030fded79 100644 (file)
@@ -11,11 +11,11 @@ Variable::Magic - Associate user-defined magic to variables from Perl.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
@@ -50,7 +50,7 @@ This magic is a little special : it is called when the 'size' or the 'length' of
 
 =item C<clear>
 
-This magic is invoked when the variable is reset, such as when an array is emptied. Please note that this is different from undefining the variable, even though the magic is called when the reset is a result of the undefine (e.g. for an array).
+This magic is invoked when the variable is reset, such as when an array is emptied. Please note that this is different from undefining the variable, even though the magic is called when the clearing is a result of the undefine (e.g. for an array, but actually a bug prevent it to work before perl 5.9.5 - see the L<history|/PERL MAGIC HISTORY>).
 
 =item C<free>
 
@@ -60,6 +60,24 @@ This last one can be considered as an object destructor. It happens when the var
 
 To prevent any clash between different magics defined with this module, an unique numerical signature is attached to each kind of magic (i.e. each set of callbacks for magic operations).
 
+=head1 PERL MAGIC HISTORY
+
+=head2 B<5.9.3>
+
+=over 4
+
+=item 'len' magic is no longer called when pushing an element into a magic array.
+
+=back
+
+=head2 B<5.9.5>
+
+=over 4
+
+=item 'clear' magic wasn't invoked when undefining an array. The bug is fixed as of this version.
+
+=back
+
 =head1 CONSTANTS
 
 =head2 C<SIG_MIN>
index 6f9a8a17fcc80d927340f6181253410d0e466794..62f41456e6103af03504cf15f9b0267f2c8030c4 100644 (file)
@@ -54,7 +54,7 @@ $a[3] = 'd';
 ok(check(), 'array : assign new element');
 
 push @a, 'x';
-++$x[1]; ++$x[2];
+++$x[1]; ++$x[2] unless $^V && $^V gt 5.9.2; # since 5.9.3
 ok(check(), 'array : push');
 
 pop @a;
@@ -87,12 +87,13 @@ ok(check(), 'array : for');
 
 {
  my @b = @n;
-# cast @b, $wiz;
+ cast @b, $wiz;
 }
-#++$x[4];
+++$x[4];
 ok(check(), 'array : scope end');
 
 undef @a;
+++$x[3] if $^V && $^V gt 5.9.4; # since 5.9.5 - see #43357
 ok(check(), 'array : undef');
 
 dispell @a, $wiz;
index 74eabb81ab038980349add35fc474a56eae7e036..44510dc10224d09543105a9448f5cd20f4ac0b62 100644 (file)
@@ -64,9 +64,9 @@ ok(check(), 'hash : each');
 
 {
  my %b = %n;
-# cast %b, $wiz;
+ cast %b, $wiz;
 }
-#++$x[4];
+++$x[4];
 ok(check(), 'hash : scope end');
 
 undef %a;
diff --git a/t/34-glob.t b/t/34-glob.t
new file mode 100644 (file)
index 0000000..a1ece33
--- /dev/null
@@ -0,0 +1,52 @@
+#!perl -T
+
+use Test::More;
+
+eval "use Symbol qw/gensym/";
+if ($@) {
+ plan skip_all => "Symbol::gensym required for testing magic for globs";
+} else {
+ plan tests => 7;
+}
+
+use Variable::Magic qw/wizard cast dispell/;
+
+my @c = (0) x 5;
+my @x = (0) x 5;
+
+sub check {
+ for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; }
+ return 1;
+}
+
+my $i = -1;
+my $wiz = wizard get   => sub { ++$c[0] },
+                 set   => sub { ++$c[1] },
+                 len   => sub { ++$c[2] },
+                 clear => sub { ++$c[3] },
+                 free  => sub { ++$c[4] };
+ok(check(), 'glob : create wizard');
+
+local *a = gensym();
+
+cast *a, $wiz;
+ok(check(), 'glob : cast');
+
+local *b = *a;
+ok(check(), 'glob : assign to');
+
+*a = gensym();
+++$x[1];
+ok(check(), 'glob : assign');
+
+{
+ local *b = gensym();
+ cast *b, $wiz;
+}
+ok(check(), 'glob : scope end');
+
+undef *a;
+ok(check(), 'glob : undef');
+
+dispell *a, $wiz;
+ok(check(), 'glob : dispell');