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