Debian Codegraph @

t/04pp.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
7
8 # Some hackery to import the PP emulation
9 require Devel::Refcount;
10 require B;
11 *refcount = \&Devel::Refcount::_refcount_pp;
12
13 use Symbol qw( gensym );
14
15 my %refs = (
16 SCALAR => do { my $var; \$var },
17 ARRAY => [],
18 HASH => +{},
19 # This magic is to ensure the code ref is new, not shared. To be a new one
20 # it has to contain a unique pad.
21 CODE => do { my $var; sub { $var } },
22 GLOB => gensym(),
23 Regexp => do { my $var; qr/foo(?{ $var = 1 })/ },
24 );
25
26 is( refcount($refs{SCALAR}), 1, 'refcount(SCALAR) is 1');
27 is( refcount($refs{ARRAY}), 1, 'refcount(ARRAY) is 1');
28 is( refcount($refs{HASH}), 1, 'refcount(HASH) is 1');
29 is( refcount($refs{CODE}), 1, 'refcount(CODE) is 1');
30 is( refcount($refs{GLOB}), 1, 'refcount(GLOB) is 1');
31 is( refcount($refs{Regexp}), 1, 'refcount(Regexp) is 1');
32
33 my %otherrefs = %refs;
34 # Hope they're all 2 now
35
36 is( refcount($refs{SCALAR}), 2, 'refcount(SCALAR) is now 2');
37 is( refcount($refs{ARRAY}), 2, 'refcount(ARRAY) is now 2');
38 is( refcount($refs{HASH}), 2, 'refcount(HASH) is now 2');
39 is( refcount($refs{CODE}), 2, 'refcount(CODE) is now 2');
40 is( refcount($refs{GLOB}), 2, 'refcount(GLOB) is now 2');
41 is( refcount($refs{Regexp}), 2, 'refcount(Regexp) is now 2');