line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Util ; |
2
|
|
|
|
|
|
|
$VERSION = 2.40 ; |
3
|
4
|
|
|
4
|
|
68335
|
use 5.006_001 ; |
|
4
|
|
|
|
|
12
|
|
4
|
4
|
|
|
4
|
|
18
|
use strict ; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
115
|
|
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
|
|
19
|
; $Carp::Internal{+__PACKAGE__}++ |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
993
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
; sub import |
13
|
|
|
|
|
|
|
{ return unless @_ |
14
|
7
|
50
|
|
7
|
|
5590
|
; require Exporter |
15
|
7
|
|
|
|
|
33
|
; our @ISA = 'Exporter' |
|
7
|
|
|
|
|
75
|
|
16
|
7
|
|
|
|
|
18
|
; our @EXPORT_OK = qw| load |
17
|
|
|
|
|
|
|
gather |
18
|
|
|
|
|
|
|
blessed |
19
|
|
|
|
|
|
|
classes |
20
|
|
|
|
|
|
|
| |
21
|
7
|
|
|
|
|
4751
|
; $_[0]->export_to_level(1, @_) |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
; sub load |
25
|
3
|
50
|
|
3
|
1
|
1402
|
{ local $_ = $_[0] if defined $_[0] |
26
|
3
|
|
|
|
|
161
|
; my $r = eval "require $_;" |
27
|
3
|
100
|
|
|
|
23296
|
; if ($@) |
28
|
2
|
|
|
|
|
10
|
{ (my $c = $_.'.pm') =~ s|\b::\b|/|g |
29
|
4
|
|
|
|
|
603
|
; no strict 'refs' |
30
|
4
|
|
|
4
|
|
20
|
; croak $@ if $@ !~ /^Can't locate $c in \@INC/ |
|
4
|
|
|
|
|
4
|
|
31
|
2
|
100
|
33
|
|
|
40
|
|| not grep { /[^:][^:]\z/ } keys %{$_.'::'} |
|
1
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
182
|
|
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
8
|
; $r |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
; sub gather (&$;$) |
37
|
5
|
|
|
5
|
1
|
2035
|
{ my( $code, $symbol, $packages ) = @_ |
38
|
4
|
|
|
|
|
1128
|
; no strict 'refs' |
39
|
4
|
100
|
|
4
|
|
17
|
; unless ( ref $packages eq 'ARRAY' ) |
|
4
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
17
|
|
40
|
3
|
100
|
100
|
|
|
17
|
{ my $class = defined($packages) &&! ref($packages) |
|
|
|
66
|
|
|
|
|
41
|
|
|
|
|
|
|
? $packages |
42
|
|
|
|
|
|
|
: blessed($packages) || caller |
43
|
3
|
|
|
|
|
5
|
; $packages = classes($class) |
44
|
|
|
|
|
|
|
} |
45
|
5
|
|
|
|
|
10
|
; my $t = substr $symbol, 0, 1, '' |
46
|
5
|
100
|
|
|
|
178
|
; 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
|
|
|
|
|
35
|
; map { $code->() } |
53
|
15
|
|
|
|
|
8
|
map { *{$_.'::'.$symbol}{$type} } |
|
15
|
|
|
|
|
21
|
|
54
|
4
|
|
|
|
|
6
|
grep { defined( $type eq 'SCALAR' |
55
|
4
|
|
|
|
|
7
|
? ${$_.'::'.$symbol} |
56
|
16
|
100
|
|
|
|
16
|
: *{$_.'::'.$symbol}{$type} |
|
12
|
|
|
|
|
29
|
|
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
@$packages |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
; sub blessed |
63
|
14
|
100
|
|
14
|
1
|
40
|
{ local $_ = $_[0] if defined $_[0] |
64
|
14
|
100
|
100
|
|
|
76
|
; defined && length && eval{ $_->isa( ref ) } |
65
|
|
|
|
|
|
|
? ref |
66
|
|
|
|
|
|
|
: undef |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
; sub classes ($) |
70
|
5
|
|
|
5
|
1
|
65
|
{ my $class = shift |
71
|
5
|
50
|
|
|
|
13
|
; return () unless $class |
72
|
5
|
|
66
|
|
|
8
|
; $class = blessed($class) || $class |
73
|
5
|
|
|
|
|
10
|
; my @stack = ($class) |
74
|
5
|
|
|
|
|
11
|
; my %skip = ($class => 1) |
75
|
5
|
|
|
|
|
4
|
; my (@classes, $c) |
76
|
5
|
|
|
|
|
12
|
; while ( @stack ) |
77
|
23
|
50
|
33
|
|
|
82
|
{ next unless defined($c = shift @stack) && length $c |
78
|
23
|
|
|
|
|
26
|
; unshift @classes, $c |
79
|
4
|
|
|
4
|
|
18
|
; no strict 'refs'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
332
|
|
80
|
23
|
100
|
|
|
|
12
|
; unshift @stack, map{ $skip{$_}++ ? () : $_ } @{$c.'::ISA'} |
|
22
|
|
|
|
|
56
|
|
|
23
|
|
|
|
|
55
|
|
81
|
|
|
|
|
|
|
} |
82
|
5
|
100
|
|
|
|
34
|
; wantarray ? @classes : \@classes |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
; 1 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |