File: Util_pm

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 11,840 kB
  • sloc: perl: 95,064; ansic: 14,522; makefile: 49; sh: 18
file content (63 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download | duplicates (10)
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
61
62
63
#Extra stuff

our $DEFAULT_UNLOAD_METHOD ||= "unload_package_pp";

sub unload_package {
    goto &$DEFAULT_UNLOAD_METHOD;
}

sub unload_package_pp {
    my $package = shift;
    no strict 'refs';
    my $tab = \%{ $package . '::' };

    # below we assign to a symbol first before undef'ing it, to avoid
    # nuking aliases. If we undef directly we may undef not only the
    # alias but the original function as well

    for (keys %$tab) {
        #Skip sub stashes
        next if /::$/;

        my $fullname = join '::', $package, $_;
        # code/hash/array/scalar might be imported make sure the gv
        # does not point elsewhere before undefing each
        if (%$fullname) {
            *{$fullname} = {};
            undef %$fullname;
        }
        if (@$fullname) {
            *{$fullname} = [];
            undef @$fullname;
        }
        if ($$fullname) {
            my $tmp; # argh, no such thing as an anonymous scalar
            *{$fullname} = \$tmp;
            undef $$fullname;
        }
        if (defined &$fullname) {
            no warnings;
            local $^W = 0;
            if (defined(my $p = prototype $fullname)) {
                *{$fullname} = eval "sub ($p) {}";
            }
            else {
                *{$fullname} = sub {};
            }
            undef &$fullname;
        }
        if (*{$fullname}{IO}) {
            local $@;
            eval {
                if (fileno $fullname) {
                    close $fullname;
                }
            };
        }
    }

    #Wipe from %INC
    $package =~ s[::][/]g;
    $package .= '.pm';
    delete $INC{$package};
}