line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Util ; |
2
|
|
|
|
|
|
|
$VERSION = 2.41 ; |
3
|
4
|
|
|
4
|
|
259172
|
use 5.006_001 ; |
|
4
|
|
|
|
|
46
|
|
4
|
4
|
|
|
4
|
|
18
|
use strict ; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
89
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# This file uses the "Perlish" coding style |
7
|
|
|
|
|
|
|
# please read http://perl.4pro.net/perlish_coding_style.html |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
; use Carp |
10
|
4
|
|
|
4
|
|
16
|
; $Carp::Internal{+__PACKAGE__}++ |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
767
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
; sub import |
13
|
|
|
|
|
|
|
{ return unless @_ |
14
|
7
|
50
|
|
7
|
|
694
|
; require Exporter |
15
|
7
|
|
|
|
|
31
|
; our @ISA = 'Exporter' |
|
7
|
|
|
|
|
116
|
|
16
|
7
|
|
|
|
|
27
|
; our @EXPORT_OK = qw| load |
17
|
|
|
|
|
|
|
gather |
18
|
|
|
|
|
|
|
blessed |
19
|
|
|
|
|
|
|
classes |
20
|
|
|
|
|
|
|
| |
21
|
7
|
|
|
|
|
4795
|
; $_[0]->export_to_level(1, @_) |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
; sub load |
25
|
3
|
50
|
|
3
|
1
|
1302
|
{ local $_ = $_[0] if defined $_[0] |
26
|
3
|
|
|
|
|
121
|
; my $r = eval "require $_;" |
27
|
3
|
100
|
|
|
|
28307
|
; if ($@) |
28
|
2
|
|
|
|
|
11
|
{ (my $c = $_.'.pm') =~ s|\b::\b|/|g |
29
|
4
|
|
|
|
|
527
|
; no strict 'refs' |
30
|
4
|
|
|
4
|
|
24
|
; croak $@ if $@ !~ /^Can't locate $c in \@INC/ |
|
4
|
|
|
|
|
6
|
|
31
|
2
|
100
|
66
|
|
|
30
|
|| not grep { /[^:][^:]\z/ } keys %{$_.'::'} |
|
1
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
169
|
|
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
8
|
; $r |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
; sub gather (&$;$) |
37
|
5
|
|
|
5
|
1
|
2431
|
{ my( $code, $symbol, $packages ) = @_ |
38
|
4
|
|
|
|
|
1135
|
; no strict 'refs' |
39
|
4
|
100
|
|
4
|
|
23
|
; unless ( ref $packages eq 'ARRAY' ) |
|
4
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
17
|
|
40
|
3
|
100
|
100
|
|
|
24
|
{ my $class = defined($packages) &&! ref($packages) |
|
|
|
66
|
|
|
|
|
41
|
|
|
|
|
|
|
? $packages |
42
|
|
|
|
|
|
|
: blessed($packages) || caller |
43
|
3
|
|
|
|
|
12
|
; $packages = classes($class) |
44
|
|
|
|
|
|
|
} |
45
|
5
|
|
|
|
|
12
|
; my $t = substr $symbol, 0, 1, '' |
46
|
5
|
100
|
|
|
|
215
|
; my $type = $t eq '*' ? 'GLOB' |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
47
|
|
|
|
|
|
|
: $t eq '&' ? 'CODE' |
48
|
|
|
|
|
|
|
: $t eq '%' ? 'HASH' |
49
|
|
|
|
|
|
|
: $t eq '@' ? 'ARRAY' |
50
|
|
|
|
|
|
|
: $t eq '$' ? 'SCALAR' |
51
|
|
|
|
|
|
|
: croak 'Identifier must start with [*&%@$], died' |
52
|
15
|
|
|
|
|
42
|
; map { $code->() } |
53
|
15
|
|
|
|
|
13
|
map { *{$_.'::'.$symbol}{$type} } |
|
15
|
|
|
|
|
27
|
|
54
|
4
|
|
|
|
|
9
|
grep { defined( $type eq 'SCALAR' |
55
|
4
|
|
|
|
|
8
|
? ${$_.'::'.$symbol} |
56
|
16
|
100
|
|
|
|
21
|
: *{$_.'::'.$symbol}{$type} |
|
12
|
|
|
|
|
36
|
|
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
@$packages |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
; sub blessed |
63
|
14
|
100
|
|
14
|
1
|
122
|
{ local $_ = $_[0] if defined $_[0] |
64
|
14
|
100
|
100
|
|
|
78
|
; defined && length && eval{ $_->isa( ref ) } |
65
|
|
|
|
|
|
|
? ref |
66
|
|
|
|
|
|
|
: undef |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
; sub classes ($) |
70
|
5
|
|
|
5
|
1
|
163
|
{ my $class = shift |
71
|
5
|
50
|
|
|
|
15
|
; return () unless $class |
72
|
5
|
|
66
|
|
|
11
|
; $class = blessed($class) || $class |
73
|
5
|
|
|
|
|
11
|
; my @stack = ($class) |
74
|
5
|
|
|
|
|
11
|
; my %skip = ($class => 1) |
75
|
5
|
|
|
|
|
8
|
; my (@classes, $c) |
76
|
5
|
|
|
|
|
11
|
; while ( @stack ) |
77
|
23
|
50
|
33
|
|
|
69
|
{ next unless defined($c = shift @stack) && length $c |
78
|
23
|
|
|
|
|
77
|
; unshift @classes, $c |
79
|
4
|
|
|
4
|
|
26
|
; no strict 'refs'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
380
|
|
80
|
23
|
100
|
|
|
|
26
|
; unshift @stack, map{ $skip{$_}++ ? () : $_ } @{$c.'::ISA'} |
|
22
|
|
|
|
|
69
|
|
|
23
|
|
|
|
|
64
|
|
81
|
|
|
|
|
|
|
} |
82
|
5
|
100
|
|
|
|
27
|
; wantarray ? @classes : \@classes |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
; 1 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |