1#!/usr/bin/perl -Tw
2
3require 5;
4
5use strict;
6
7use Test::More tests => 1;
8
9BEGIN {
10    use_ok( 'Locale::Maketext' );
11}
12
13my @out;
14push @out,
15    "\n\nPerl v",
16    defined($^V) ? sprintf('%vd', $^V) : $],
17    " under $^O ",
18    (defined(&Win32::BuildNumber) and defined &Win32::BuildNumber())
19    ? ('(Win32::BuildNumber ', &Win32::BuildNumber(), ')') : (),
20    (defined $MacPerl::Version)
21    ? ("(MacPerl version $MacPerl::Version)") : (),
22    "\n"
23;
24
25# Ugly code to walk the symbol tables:
26my %v;
27my @stack = ('');  # start out in %::
28my $this;
29my $count = 0;
30my $pref;
31while(@stack) {
32    $this = shift @stack;
33    die 'Too many packages?' if ++$count > 1000;
34    next if exists $v{$this};
35    next if $this eq 'main'; # %main:: is %::
36
37    no strict 'refs';
38    if ( defined ${$this . '::VERSION'} ) {
39        $v{$this} = ${$this . '::VERSION'}
40    }
41    elsif (
42        defined *{$this . '::ISA'} or defined &{$this . '::import'}
43            or ($this ne '' and grep defined *{$_}{'CODE'}, values %{$this . '::'})
44        # If it has an ISA, an import, or any subs...
45    ) {
46        # It's a class/module with no version.
47        $v{$this} = undef;
48    }
49    else {
50        # It's probably an unpopulated package.
51        ## $v{$this} = '...';
52    }
53
54    $pref = length($this) ? "$this\::" : '';
55    push @stack, map m/^(.+)::$/ ? "$pref$1" : (), keys %{$this . '::'};
56}
57push @out, " Modules in memory:\n";
58delete @v{'', '[none]'};
59foreach my $p (sort {lc($a) cmp lc($b)} keys %v) {
60    my $indent = ' ' x (2 + ($p =~ tr/:/:/));
61    push @out,  '  ', $indent, $p, defined($v{$p}) ? " v$v{$p};\n" : ";\n";
62}
63push @out, sprintf "[at %s (local) / %s (GMT)]\n", scalar(gmtime), scalar(localtime);
64my $x = join '', @out;
65$x =~ s/^/#/mg;
66print $x;
67
68my $ascii = (chr(65) eq 'A') ? 'an ASCII' : 'a non-ASCII';
69print "# Running in $ascii world.\n";
70
71print "# \@INC:\n", map("#   [$_]\n", @INC), "#\n#\n";
72
73print "# \%INC:\n";
74foreach my $x (sort {lc($a) cmp lc($b)} keys %INC) {
75    print "#   [$x] = [", $INC{$x} || '', "]\n";
76}
77