File: packages.pl

package info (click to toggle)
libdata-structure-util-perl 0.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 862; makefile: 8
file content (60 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;
use blib;
use TEST;
use Data::Dumper;
use Data::Structure::Util qw( has_circular_ref );


sub check_globals {
  my $package = shift || 'main';
  next_package($package);
}

sub next_package {
  my $pkg = shift;
  no strict 'refs';
  
  for my $key (%{"$pkg".'::'}) {
    next if ($key =~ /^\*/);
    if ($key =~ /(.+)\:\:$/) {
      if ($1 ne $pkg) {
        next_package($pkg . '::' . $1);
      }
    }

    my $scalar = ${"$pkg\::$key"};
    if (ref $scalar) {
      if (my $ref = has_circular_ref($scalar)) {
        warn "###### CIRCULAR REF DETECTED IN \$$pkg\::$key\n";
      }
    }
    
    my $hash = \%{"$pkg\::$key"};
    if (%$hash) {
      if (my $ref = has_circular_ref($hash)) {
        warn "###### CIRCULAR REF DETECTED IN \%$pkg\::$key\n";
      }
    }
  
    my $array = \@{"$pkg\::$key"};
    if (@$array) {
      if (my $ref = has_circular_ref($array)) {
        warn "###### CIRCULAR REF DETECTED IN \@$pkg\::$key\n";
      }
    }
  
  }
}

=head1 NAME

packages.pl

=head1 DESCRIPTION

Search through all the global variables in all packagse 
for any circular reference.

=cut