line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::MakeMethods::Emulator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 1.009; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
######################################################################## |
6
|
|
|
|
|
|
|
### IMPORT BEHAVIOR: import(), _handle_namespace() |
7
|
|
|
|
|
|
|
######################################################################## |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@EXPORT_OK = qw( namespace_capture namespace_release ); |
10
|
|
|
|
|
|
|
sub import { |
11
|
|
|
|
|
|
|
|
12
|
10
|
100
|
66
|
10
|
|
97
|
if ( scalar @_ == 2 and $_[1] eq '-isasubclass' ) { |
13
|
8
|
|
|
|
|
39
|
splice @_, 1, 1; |
14
|
8
|
|
|
|
|
31
|
my $target_class = ( caller )[0]; |
15
|
47
|
|
|
47
|
|
263
|
no strict; |
|
47
|
|
|
|
|
89
|
|
|
47
|
|
|
|
|
18330
|
|
16
|
8
|
|
|
|
|
16
|
push @{"$target_class\::ISA"}, $_[0]; |
|
8
|
|
|
|
|
120
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
10
|
50
|
|
|
|
57
|
if ( $_[0] eq __PACKAGE__ ) { |
20
|
10
|
50
|
|
|
|
1201
|
require Exporter and goto &Exporter::import # lazy Exporter |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _handle_namespace { |
25
|
23
|
|
|
23
|
|
41
|
my $class = shift; |
26
|
23
|
|
|
|
|
35
|
my $emulation_target = shift; |
27
|
23
|
100
|
|
|
|
281
|
my $firstarg = shift or return; |
28
|
18
|
|
50
|
|
|
153
|
my $take = shift || '-take_namespace'; |
29
|
18
|
|
50
|
|
|
100
|
my $release = shift || '-release_namespace'; |
30
|
|
|
|
|
|
|
|
31
|
18
|
100
|
|
|
|
286
|
if ( $firstarg eq $take) { |
|
|
50
|
|
|
|
|
|
32
|
7
|
|
|
|
|
60
|
Class::MakeMethods::Emulator::namespace_capture($class, $emulation_target); |
33
|
7
|
|
|
|
|
39
|
return 1; |
34
|
|
|
|
|
|
|
} elsif ( $firstarg eq $release) { |
35
|
0
|
|
|
|
|
0
|
Class::MakeMethods::Emulator::namespace_release($class, $emulation_target); |
36
|
0
|
|
|
|
|
0
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
######################################################################## |
41
|
|
|
|
|
|
|
### NAMESPACE MUNGING: _namespace_capture(), _namespace_release() |
42
|
|
|
|
|
|
|
######################################################################## |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub namespace_capture { |
45
|
10
|
|
|
10
|
0
|
19
|
my $source_package = shift; |
46
|
10
|
|
|
|
|
28
|
my $target_package = shift; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# warn "Mapping $source_package over $target_package \n"; |
49
|
|
|
|
|
|
|
|
50
|
10
|
|
|
|
|
27
|
my $source_file = "$source_package.pm"; |
51
|
10
|
|
|
|
|
89
|
$source_file =~ s{::}{/}g; |
52
|
|
|
|
|
|
|
|
53
|
10
|
|
|
|
|
56
|
my $target_file = "$target_package.pm"; |
54
|
10
|
|
|
|
|
33
|
$target_file =~ s{::}{/}g; |
55
|
|
|
|
|
|
|
|
56
|
10
|
|
|
|
|
31
|
my $temp_package = $source_package . '::Target::' . $target_package; |
57
|
10
|
|
|
|
|
30
|
my $temp_file = "$temp_package.pm"; |
58
|
10
|
|
|
|
|
55
|
$temp_file =~ s{::}{/}g; |
59
|
|
|
|
|
|
|
|
60
|
47
|
|
|
47
|
|
318
|
no strict; |
|
47
|
|
|
|
|
110
|
|
|
47
|
|
|
|
|
10364
|
|
61
|
10
|
50
|
|
|
|
20
|
unless ( ${$temp_package . "::TargetCaptured"} ++ ) { |
|
10
|
|
|
|
|
159
|
|
62
|
10
|
|
|
|
|
19
|
*{$temp_package . "::"} = *{$target_package . "::"}; |
|
10
|
|
|
|
|
151
|
|
|
10
|
|
|
|
|
56
|
|
63
|
10
|
|
|
|
|
75
|
$::INC{$temp_file} = $::INC{$target_file}; |
64
|
|
|
|
|
|
|
} |
65
|
10
|
|
|
|
|
20
|
*{$target_package . "::"} = *{$source_package . "::"}; |
|
10
|
|
|
|
|
243
|
|
|
10
|
|
|
|
|
37
|
|
66
|
10
|
|
|
|
|
70
|
$::INC{$target_file} = $::INC{$source_file} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub namespace_release { |
70
|
0
|
|
|
0
|
0
|
|
my $source_package = shift; |
71
|
0
|
|
|
|
|
|
my $target_package = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $target_file = "$target_package.pm"; |
74
|
0
|
|
|
|
|
|
$target_file =~ s{::}{/}g; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $temp_package = $source_package . '::Target::' . $target_package; |
77
|
0
|
|
|
|
|
|
my $temp_file = "$temp_package.pm"; |
78
|
0
|
|
|
|
|
|
$temp_file =~ s{::}{/}g; |
79
|
|
|
|
|
|
|
|
80
|
47
|
|
|
47
|
|
626
|
no strict; |
|
47
|
|
|
|
|
367
|
|
|
47
|
|
|
|
|
5558
|
|
81
|
0
|
0
|
|
|
|
|
unless ( ${"${temp_package}::TargetCaptured"} ) { |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
Carp::croak("Can't _namespace_release: -take_namespace not called yet."); |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
*{$target_package . "::"} = *{$temp_package. "::"}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$::INC{$target_file} = $::INC{$temp_file}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
######################################################################## |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |