line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pcore::Util::Class; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
18
|
use Pcore; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
15
|
|
4
|
3
|
|
|
3
|
|
19
|
use Sub::Util qw[]; ## no critic qw[Modules::ProhibitEvilModules] |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2381
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
0
|
6
|
sub load ( $class, @ ) { |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
5
|
|
7
|
4
|
|
|
|
|
18
|
my %args = ( |
8
|
|
|
|
|
|
|
ns => undef, |
9
|
|
|
|
|
|
|
isa => undef, # InstanceOf |
10
|
|
|
|
|
|
|
does => undef, # ConsumerOf |
11
|
|
|
|
|
|
|
splice @_, 1, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
|
|
9
|
my $module; |
15
|
|
|
|
|
|
|
|
16
|
4
|
50
|
|
|
|
17
|
if ( substr( $class, -3 ) eq '.pm' ) { |
17
|
0
|
|
|
|
|
0
|
$module = $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
$class =~ s[/][::]smg; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
substr $class, -3, 3, q[]; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
4
|
|
|
|
|
12
|
$class = resolve_class_name( $class, $args{ns} ); |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
18
|
$module = ( $class =~ s[::][/]smgr ) . '.pm'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
1298
|
require $module; |
30
|
|
|
|
|
|
|
|
31
|
4
|
50
|
33
|
|
|
24
|
die qq[Error loading class "$class". Class must be instance of "$args{isa}"] if $args{isa} && !$class->isa( $args{isa} ); |
32
|
|
|
|
|
|
|
|
33
|
4
|
50
|
33
|
|
|
18
|
die qq[Error loading class "$class". Class must be consumer of "$args{does}"] if $args{does} && !$class->does( $args{does} ); |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
22
|
return $class; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
6
|
0
|
9
|
sub find ( $class, @ ) { |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
7
|
|
39
|
6
|
|
|
|
|
29
|
my %args = ( |
40
|
|
|
|
|
|
|
ns => undef, |
41
|
|
|
|
|
|
|
splice @_, 1, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
11
|
my $class_filename; |
45
|
|
|
|
|
|
|
|
46
|
6
|
50
|
|
|
|
24
|
if ( $class =~ /[.]pm\z/sm ) { |
47
|
0
|
|
|
|
|
0
|
$class_filename = $class; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
6
|
|
|
|
|
20
|
$class = resolve_class_name( $class, $args{ns} ); |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
30
|
$class_filename = ( $class =~ s[::][/]smgr ) . q[.pm]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
6
|
|
|
|
|
14
|
my $found; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# find class in @INC |
58
|
6
|
|
|
|
|
11
|
for my $inc ( grep { !ref } @INC ) { |
|
54
|
|
|
|
|
90
|
|
59
|
22
|
100
|
|
|
|
305
|
if ( -f "$inc/$class_filename" ) { |
60
|
4
|
|
|
|
|
13
|
$found = "$inc/$class_filename"; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
9
|
last; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
6
|
|
|
|
|
51
|
return $found; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
10
|
|
|
10
|
0
|
18
|
sub resolve_class_name ( $class, $ns = undef ) { |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
13
|
|
70
|
10
|
50
|
|
|
|
30
|
if ( substr( $class, 0, 1 ) eq '+' ) { |
71
|
0
|
|
|
|
|
0
|
return $class; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
10
|
50
|
|
|
|
42
|
return $ns ? "${ns}::$class" : $class; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub set_sub_prototype { |
79
|
0
|
|
|
0
|
0
|
|
return &Sub::Util::set_prototype; ## no critic qw[Subroutines::ProhibitAmpersandSigils] |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_sub_prototype { |
83
|
0
|
|
|
0
|
0
|
|
return &Sub::Util::prototype; ## no critic qw[Subroutines::ProhibitAmpersandSigils] |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# allow to specify name as '::<name>', caller namespace will be used as full sub name |
87
|
|
|
|
|
|
|
sub set_subname { |
88
|
0
|
|
|
0
|
0
|
|
return &Sub::Util::set_subname; ## no critic qw[Subroutines::ProhibitAmpersandSigils] |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_sub_name { |
92
|
0
|
|
|
0
|
0
|
|
my ( $package, $name ) = &Sub::Util::subname =~ /^(.+)::(.+)$/sm; ## no critic qw[Subroutines::ProhibitAmpersandSigils] |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $name; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_sub_fullname { |
98
|
0
|
|
|
0
|
0
|
|
my $full_name = &Sub::Util::subname; ## no critic qw[Subroutines::ProhibitAmpersandSigils] |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if (wantarray) { |
101
|
0
|
|
|
|
|
|
my ( $package, $name ) = $full_name =~ /^(.+)::(.+)$/sm; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return $name, $package; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
|
return $full_name; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
=pod |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding utf8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |