From: Vincent Pit Date: Sun, 29 Jun 2008 16:24:18 +0000 (+0200) Subject: Importing Variable-Magic-0.02.tar.gz X-Git-Tag: v0.02^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=ad7c749baf8ebc2ff3e49d44b414f67f13f4ebf2 Importing Variable-Magic-0.02.tar.gz --- diff --git a/Changes b/Changes index 1cf4720..bcd60be 100644 --- 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. diff --git a/MANIFEST b/MANIFEST index 5c2edd7..f07ba3e 100644 --- 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 diff --git a/META.yml b/META.yml index cb4d046..afc6683 100644 --- 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 diff --git a/Magic.xs b/Magic.xs index 2f6db15..be5e8f8 100644 --- 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 541b09d..c7ce74e 100644 --- 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. diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index 9944a91..07fa6f5 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -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 -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). =item C @@ -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 diff --git a/t/31-array.t b/t/31-array.t index 6f9a8a1..62f4145 100644 --- a/t/31-array.t +++ b/t/31-array.t @@ -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; diff --git a/t/32-hash.t b/t/32-hash.t index 74eabb8..44510dc 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -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 index 0000000..a1ece33 --- /dev/null +++ b/t/34-glob.t @@ -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');