summaryrefslogtreecommitdiff
path: root/lib/builtin.t
diff options
context:
space:
mode:
authorJames Raspass <jraspass@gmail.com>2022-06-11 23:33:31 +0100
committerTony Cook <tony@develop-help.com>2022-07-05 11:17:31 +1000
commita02b8151f9b69201233f9ca5774db280c34684de (patch)
treec783043e3e74ece3c98f4c71d828aa4eb571adc5 /lib/builtin.t
parentc5327cb77526e4e4c7bb83e24be20ac48e85b1fa (diff)
downloadperl-a02b8151f9b69201233f9ca5774db280c34684de.tar.gz
Add builtin::is_tainted
Also tweak the implementation of the other two boolean builtins (is_bool & is_weak) to be slightly more efficient.
Diffstat (limited to 'lib/builtin.t')
-rw-r--r--lib/builtin.t32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/builtin.t b/lib/builtin.t
index e601d9ec5b..31a4b30048 100644
--- a/lib/builtin.t
+++ b/lib/builtin.t
@@ -1,4 +1,4 @@
-#!./perl
+#!./perl -T
BEGIN {
chdir 't' if -d 't';
@@ -6,15 +6,14 @@ BEGIN {
set_up_inc('../lib');
}
-use strict;
-use warnings;
+use v5.36;
no warnings 'experimental::builtin';
package FetchStoreCounter {
- sub new { my $class = shift; return bless [@_], $class }
- sub TIESCALAR { return shift->new(@_) }
- sub FETCH { ${shift->[0]}++ }
- sub STORE { ${shift->[1]}++ }
+ sub TIESCALAR($class, @args) { bless \@args, $class }
+
+ sub FETCH($self) { $self->[0]->$*++ }
+ sub STORE($self, $) { $self->[1]->$*++ }
}
# booleans
@@ -47,7 +46,7 @@ package FetchStoreCounter {
is($fetchcount, 1, 'is_bool() invokes FETCH magic');
$tied = is_bool(false);
- is($storecount, 1, 'is_bool() TARG invokes STORE magic');
+ is($storecount, 1, 'is_bool() invokes STORE magic');
}
# weakrefs
@@ -342,6 +341,23 @@ TODO: {
is(trim($str2), "Hello world!", "Trim on an our \$var");
}
+# is_tainted
+{
+ use builtin qw( is_tainted );
+
+ is(is_tainted($0), !!${^TAINT}, "\$0 is tainted (if tainting is supported)");
+ ok(!is_tainted($1), "\$1 isn't tainted");
+
+ # Invokes magic
+ tie my $tied, FetchStoreCounter => (\my $fetchcount, \my $storecount);
+
+ my $_dummy = is_tainted($tied);
+ is($fetchcount, 1, 'is_tainted() invokes FETCH magic');
+
+ $tied = is_tainted($0);
+ is($storecount, 1, 'is_tainted() invokes STORE magic');
+}
+
# vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4
done_testing();