… | |
… | |
19 | |
19 | |
20 | package Test; |
20 | package Test; |
21 | |
21 | |
22 | use Devel::FindRef; |
22 | use Devel::FindRef; |
23 | use Scalar::Util; |
23 | use Scalar::Util; |
24 | |
24 | |
25 | our $var = "hi\n"; |
25 | our $var = "hi\n"; |
26 | my $global_my = \$var; |
26 | my $global_my = \$var; |
27 | our %global_hash = (ukukey => \$var); |
27 | our %global_hash = (ukukey => \$var); |
28 | our $global_hashref = { ukukey2 => \$var }; |
28 | our $global_hashref = { ukukey2 => \$var }; |
29 | |
29 | |
30 | sub testsub { |
30 | sub testsub { |
31 | my $testsub_local = $global_hashref; |
31 | my $testsub_local = $global_hashref; |
32 | print Devel::FindRef::track \$var; |
32 | print Devel::FindRef::track \$var; |
33 | } |
33 | } |
34 | |
34 | |
35 | |
35 | |
… | |
… | |
70 | a temporary on the stack. |
70 | a temporary on the stack. |
71 | |
71 | |
72 | It is a bit convoluted to read, but basically it says that the value |
72 | It is a bit convoluted to read, but basically it says that the value |
73 | stored in $var is referenced by: |
73 | stored in $var is referenced by: |
74 | |
74 | |
75 | - in the lexical $closure_var (0x8abcc8), which is inside an |
75 | - the lexical $closure_var (0x8abcc8), which is inside an instantiated |
76 | instantiated closure, which in turn is used quite a bit. |
76 | closure, which in turn is used quite a bit. |
77 | - in the package-level lexical $global_my. |
77 | - the package-level lexical $global_my. |
78 | - in the global package variable named $Test::var. |
78 | - the global package variable named $Test::var. |
79 | - in the hash element "ukukey2", in the hash in the my variable |
79 | - the hash element "ukukey2", in the hash in the my variable |
80 | $testsub_local in the sub "Test::testsub" and also in the hash |
80 | $testsub_local in the sub "Test::testsub" and also in the hash |
81 | "$referenced by Test::hash2". |
81 | "$referenced by Test::hash2". |
82 | - in the hash element with key "ukukey" in the hash stored in |
82 | - the hash element with key "ukukey" in the hash stored in %Test::hash. |
83 | %Test::hash. |
|
|
84 | - some anonymous mortalised reference on the stack (which is caused by |
83 | - some anonymous mortalised reference on the stack (which is caused by |
85 | calling "track" with the expression "\$var", which creates the |
84 | calling "track" with the expression "\$var", which creates the |
86 | reference). |
85 | reference). |
87 | |
86 | |
88 | And all these account for six reference counts. |
87 | And all these account for six reference counts. |