]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/25-copy.t
Add support for copy magic on code prototype clone
[perl/modules/Variable-Magic.git] / t / 25-copy.t
index 394449541b3ab123f7ff015b0bf16834ab77c3a1..46e324141653d2298c32b85ad5a3b4ce948e379e 100644 (file)
@@ -8,9 +8,9 @@ use Test::More;
 use lib 't/lib';
 use VPIT::TestHelpers;
 
-use Variable::Magic qw<cast dispell>;
+use Variable::Magic qw<wizard cast dispell VMG_COMPAT_CODE_COPY_CLONE>;
 
-plan tests => 2 + ((2 * 5 + 3) + (2 * 2 + 1)) + (2 * 9 + 6) + 1;
+plan tests => 2 + ((2 * 5 + 3) + (2 * 2 + 1)) + (2 * 9 + 6) + 3 + 1;
 
 use lib 't/lib';
 use Variable::Magic::TestWatcher;
@@ -80,3 +80,23 @@ SKIP: {
 
  watch { undef %h } { }, 'tied hash undef';
 }
+
+SKIP: {
+ skip 'copy magic not called for cloned prototypes before perl 5.17.0' => 3
+                                              unless VMG_COMPAT_CODE_COPY_CLONE;
+ my $w = wizard copy => sub {
+  is ref($_[0]), 'CODE', 'first arg in copy on clone is a code ref';
+  is $_[2],      undef,  'third arg in copy on clone is undef';
+  is ref($_[3]), 'CODE', 'fourth arg in copy on clone is a code ref';
+ };
+ eval <<'TEST_COPY';
+  package X;
+  sub MODIFY_CODE_ATTRIBUTES {
+   my ($pkg, $sub) = @_;
+   &Variable::Magic::cast($sub, $w);
+   return;
+  }
+  my $i;
+  my $f = sub : Hello { $i };
+TEST_COPY
+}