/Test-Refcount-0.07/t/04reftypes.t
Perl | 37 lines | 23 code | 7 blank | 7 comment | 1 complexity | 2c4a48fe2c105997fb0d5e975a8bdf85 MD5 | raw file
Possible License(s): AGPL-1.0
- #!/usr/bin/perl -w
- use strict;
- use Test::Builder::Tester tests => 6;
- use Test::More;
- use Symbol qw( gensym );
- use Test::Refcount;
- my %refs = (
- SCALAR => do { my $var; \$var },
- ARRAY => [],
- HASH => +{},
- # This magic is to ensure the code ref is new, not shared. To be a new one
- # it has to contain a unique pad.
- CODE => do { my $var; sub { $var } },
- GLOB => gensym(),
- Regex => qr/foo/,
- );
- foreach my $type (qw( SCALAR ARRAY HASH CODE GLOB Regex )) {
- SKIP: {
- if( $type eq "Regex" and $] >= 5.011 ) {
- # Perl v5.11 seems to have odd behaviour with Regexp references. They start
- # off with a refcount of 2. Not sure if this is a bug in Perl, or my
- # assumption. Until P5P have worked it out, we'll skip this. See also
- # similar skip logic in Devel-Refcount's tests
- skip "Bleadperl", 1;
- }
- test_out( "ok 1 - anon $type ref" );
- is_refcount( $refs{$type}, 1, "anon $type ref" );
- test_test( "anon $type ref succeeds" );
- }
- }