chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan( tests => 5 );
+ plan( tests => 10 );
}
for my $arg ('', 'q[]', qw( 1 undef )) {
$x = *foo;
Internals::SvREADONLY $x, 1;
+ok Internals::SvREADONLY($x),
+ 'read-only glob copies are read-only acc. to Internals::';
eval { $x = [] };
like $@, qr/Modification of a read-only value attempted at/,
'read-only glob copies';
+Internals::SvREADONLY($x,0);
+$x = 42;
+is $x, 42, 'Internals::SvREADONLY can turn off readonliness on globs';
+
+$h{a} = __PACKAGE__;
+Internals::SvREADONLY $h{a}, 1;
+eval { $h{a} = 3 };
+like $@, qr/Modification of a read-only value attempted at/,
+ 'making a COW scalar into a read-only one';
+
+$h{b} = __PACKAGE__;
+ok !Internals::SvREADONLY($h{b}),
+ 'cows are not read-only acc. to Internals::';
+Internals::SvREADONLY($h{b},0);
+$h{b} =~ y/ia/ao/;
+is __PACKAGE__, 'main',
+ 'turning off a cow’s readonliness did not affect sharers of the same PV';
}
($s) = keys %{{pie => 3}};
-my $wasro = Internals::SvREADONLY($s);
-{
+SKIP: {
+ if (!eval { require B }) { skip "no B", 1 }
+ my $wasro = B::svref_2object(\$s)->FLAGS & &B::SVf_READONLY;
$wasro or local $TODO = "didn't have a COW";
$s =~ tr/i//;
- ok( Internals::SvREADONLY($s), "count-only tr doesn't deCOW COWs" );
+ ok( B::svref_2object(\$s)->FLAGS & &B::SVf_READONLY,
+ "count-only tr doesn't deCOW COWs" );
}
# [ RT #61520 ]
sv = SvRV(svz);
if (items == 1) {
- if (SvREADONLY(sv))
+ if (SvREADONLY(sv) && !SvIsCOW(sv))
XSRETURN_YES;
else
XSRETURN_NO;
}
else if (items == 2) {
if (SvTRUE(ST(1))) {
+ if (SvIsCOW(sv)) sv_force_normal(sv);
SvREADONLY_on(sv);
XSRETURN_YES;
}
else {
/* I hope you really know what you are doing. */
- SvREADONLY_off(sv);
+ if (!SvIsCOW(sv)) SvREADONLY_off(sv);
XSRETURN_NO;
}
}