line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Util.pm 4 2007-09-13 10:16:35Z asksol $ |
2
|
|
|
|
|
|
|
# $Source$ |
3
|
|
|
|
|
|
|
# $Author: asksol $ |
4
|
|
|
|
|
|
|
# $HeadURL: https://class-dot-model.googlecode.com/svn/trunk/lib/Class/Dot/Model/Util.pm $ |
5
|
|
|
|
|
|
|
# $Revision: 4 $ |
6
|
|
|
|
|
|
|
# $Date: 2007-09-13 12:16:35 +0200 (Thu, 13 Sep 2007) $ |
7
|
|
|
|
|
|
|
package Class::Dot::Model::Util; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
11
|
1
|
|
|
1
|
|
79
|
use version; our $VERSION = qv('0.1.3'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
90
|
use 5.006_001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
41
|
|
15
|
1
|
|
|
1
|
|
4
|
use English qw( -no_match_vars ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
16
|
1
|
|
|
1
|
|
351
|
use Params::Util qw(_ARRAY _HASHLIKE); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
17
|
1
|
|
|
1
|
|
852
|
use Class::Plugin::Util; |
|
1
|
|
|
|
|
4677
|
|
|
1
|
|
|
|
|
9
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $UPLEVEL = 2; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %EXPORT = ( |
22
|
|
|
|
|
|
|
FQDN => \&FQDN, |
23
|
|
|
|
|
|
|
install_coderef => \&install_coderef, |
24
|
|
|
|
|
|
|
push_base_class => \&push_base_class, |
25
|
|
|
|
|
|
|
run_as_call_class => \&run_as_call_class, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub import { |
29
|
2
|
|
|
2
|
|
872
|
my $class = shift; |
30
|
2
|
|
|
|
|
6
|
my $call_class = caller 0; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
14
|
while (my ($sub_name, $sub_code_ref) = each %EXPORT) { |
33
|
8
|
|
|
|
|
21
|
install_coderef( |
34
|
|
|
|
|
|
|
$sub_code_ref => $call_class, $sub_name |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
314
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub FQDN { |
42
|
9
|
|
|
9
|
1
|
81
|
return join q{::}, @_; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub install_coderef { |
46
|
8
|
|
|
8
|
1
|
14
|
my ($coderef, $package, $name) = @_; |
47
|
|
|
|
|
|
|
|
48
|
8
|
|
|
|
|
16
|
my $fqdn = join q{::}, $package, $name; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
82
|
NOSTRICT: { |
51
|
1
|
|
|
1
|
|
180
|
no strict 'refs'; ## no critic; |
|
1
|
|
|
|
|
2
|
|
|
8
|
|
|
|
|
10
|
|
52
|
8
|
|
|
|
|
6
|
*{ FQDN($package, $name) } = $coderef; |
|
8
|
|
|
|
|
15
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
8
|
|
|
|
|
34
|
return $fqdn; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub push_base_class { |
60
|
1
|
|
|
1
|
1
|
3
|
my ($base_class, $target_class) = @_; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
3
|
Class::Plugin::Util::_require_class($base_class); ## no critic |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
72325
|
if (! $target_class->isa($base_class)) { |
65
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; ## no critic |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
155
|
|
66
|
1
|
|
|
|
|
3
|
push @{ FQDN($target_class, 'ISA') }, $base_class; |
|
1
|
|
|
|
|
5
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
run_as_call_class({ |
70
|
1
|
|
|
|
|
10
|
call_class => $target_class, |
71
|
|
|
|
|
|
|
class => $base_class, |
72
|
|
|
|
|
|
|
method => 'import' |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
4
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub run_as_call_class { ## no critic |
79
|
2
|
|
|
2
|
1
|
4
|
my $class; |
80
|
|
|
|
|
|
|
my $method; |
81
|
0
|
|
|
|
|
0
|
my $call_class; |
82
|
|
|
|
|
|
|
|
83
|
2
|
100
|
|
|
|
12
|
if (_HASHLIKE($_[0])) { |
84
|
1
|
|
|
|
|
3
|
my $opts = shift; |
85
|
1
|
|
|
|
|
3
|
$class = $opts->{class}; |
86
|
1
|
|
|
|
|
2
|
$method = $opts->{method}; |
87
|
1
|
|
|
|
|
3
|
$call_class = $opts->{call_class}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
1
|
|
|
|
|
2
|
$call_class = shift; |
91
|
1
|
|
|
|
|
2
|
$method = shift; |
92
|
1
|
|
|
|
|
2
|
$class = $call_class; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
5
|
my $statement = qq{ |
96
|
|
|
|
|
|
|
package $call_class; |
97
|
|
|
|
|
|
|
\$call_class->\$method(\@_); |
98
|
|
|
|
|
|
|
}; ## no critic |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
127
|
eval qq{ $statement }; ## no critic |
101
|
|
|
|
|
|
|
|
102
|
2
|
50
|
|
|
|
110697
|
if ($EVAL_ERROR) { |
103
|
1
|
|
|
1
|
|
5
|
no warnings 'once'; ## no critic |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
98
|
|
104
|
0
|
|
|
|
|
0
|
$Carp::CallLevel = $UPLEVEL; ## no critic |
105
|
0
|
|
|
|
|
0
|
croak $EVAL_ERROR; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
9
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |