1#!perl -T 2# -*- mode: cperl ; compile-command: "cd .. ; ./Build ; prove -vb t/14-*.t" -*- 3 4BEGIN { 5 $_ = defined && /(.*)/ && $1 for @ENV{qw/ TMPDIR TEMP TMP /}; # taint vs tempfile 6 use Test::More; 7 eval "use Test::Refcount (); use Scalar::Util ()"; 8 plan skip_all => "Test::Refcount and Scalar::Util required to test refcount" if $@; 9} 10 11use Test::More tests => 3*5; 12use Test::Refcount; 13 14use strict; 15use warnings; 16 17use Test::Trap qw/ $tempfile tempfile :output(tempfile) /; 18use Test::Trap qw/ $systemsafe systemsafe :output(systemsafe) /; 19use Test::Trap qw/ $perlio perlio :output(perlio) /; 20 21our($trap); 22sub trap(&); 23for my $glob (qw(tempfile systemsafe perlio)) { 24 no strict 'refs'; 25 local *trap = *$glob; 26 () = trap { 0 }; 27 is_oneref($trap, "Basic check, with $glob: Our trap has one ref."); 28 my $copy = $trap; 29 my $prop = $trap->Prop; 30 Scalar::Util::weaken($copy); 31 Scalar::Util::weaken($prop); 32 is_oneref($copy, "Sanity check, with $glob: Our trap has one ref now."); 33 is_oneref($prop, "Sanity check, with $glob: Our trap's property collection has one ref now."); 34 () = trap { 1 }; 35 ok(!defined($copy), "Timely destruction, with $glob: Our trap has been collected now."); 36 ok(!defined($prop), "Timely destruction, with $glob: Our trap's property collection has been collected now."); 37} 38