PageRenderTime 52ms CodeModel.GetById 47ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Test-Refcount-0.07/t/04reftypes.t

#
Perl | 37 lines | 23 code | 7 blank | 7 comment | 1 complexity | 2c4a48fe2c105997fb0d5e975a8bdf85 MD5 | raw file
 1#!/usr/bin/perl -w
 2
 3use strict;
 4
 5use Test::Builder::Tester tests => 6;
 6use Test::More;
 7
 8use Symbol qw( gensym );
 9
10use Test::Refcount;
11
12my %refs = (
13   SCALAR => do { my $var; \$var },
14   ARRAY  => [],
15   HASH   => +{},
16   # This magic is to ensure the code ref is new, not shared. To be a new one
17   # it has to contain a unique pad.
18   CODE   => do { my $var; sub { $var } },
19   GLOB   => gensym(),
20   Regex  => qr/foo/,
21);
22
23foreach my $type (qw( SCALAR ARRAY HASH CODE GLOB Regex )) {
24   SKIP: {
25      if( $type eq "Regex" and $] >= 5.011 ) {
26         # Perl v5.11 seems to have odd behaviour with Regexp references. They start
27         # off with a refcount of 2. Not sure if this is a bug in Perl, or my
28         # assumption. Until P5P have worked it out, we'll skip this. See also
29         # similar skip logic in Devel-Refcount's tests
30         skip "Bleadperl", 1;
31      }
32
33      test_out( "ok 1 - anon $type ref" );
34      is_refcount( $refs{$type}, 1, "anon $type ref" );
35      test_test( "anon $type ref succeeds" );
36   }
37}