line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package as; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# make sure we have version info for this module |
4
|
|
|
|
|
|
|
$VERSION= '0.13'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# be as strict and verbose as possible |
7
|
1
|
|
|
1
|
|
58412
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# modules that we need |
11
|
1
|
|
|
1
|
|
5
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# hash containing already aliased modules |
14
|
|
|
|
|
|
|
my %ALIASED; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# make sure this is done before anything else |
17
|
|
|
|
|
|
|
BEGIN { |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# allow dirty stuff happening without anyone complaining about it |
20
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
21
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
378
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=for Explanation: |
24
|
|
|
|
|
|
|
We want to take over the standard -require- functionality so that we |
25
|
|
|
|
|
|
|
can inject ourselves in the -use- processing and to install our own |
26
|
|
|
|
|
|
|
"import" functionality. If there is no previous custom installed |
27
|
|
|
|
|
|
|
-require- handler yet, then we don't bother calling it, which should |
28
|
|
|
|
|
|
|
have some execution benefits. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
4
|
my $old= \&CORE::GLOBAL::require; |
33
|
1
|
|
|
|
|
2
|
eval { $old->() }; |
|
1
|
|
|
|
|
12
|
|
34
|
1
|
50
|
|
|
|
5
|
$old= undef if $@ =~ m#CORE::GLOBAL::require#; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# install our own -require- handler |
37
|
|
|
|
|
|
|
*CORE::GLOBAL::require = sub { |
38
|
33
|
|
|
33
|
|
11797
|
my $file= $_[0]; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# perform what was originally expected |
41
|
33
|
|
|
|
|
38
|
my $return; |
42
|
33
|
50
|
|
|
|
176
|
if ($old) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
($return)= eval { $old->($file) }; |
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# seems to be a version check |
47
|
|
|
|
|
|
|
elsif ( $file =~ m#^v?[\d\.]+$# ) { |
48
|
2
|
|
|
|
|
3
|
($return)= eval { CORE::require( 0 + $file ) }; # needs num value |
|
2
|
|
|
|
|
30
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# no special -require- action needed, already loaded before |
52
|
|
|
|
|
|
|
elsif ( $INC{$file} ) { |
53
|
24
|
|
|
|
|
32
|
$return= 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# first time -require- |
57
|
|
|
|
|
|
|
else { |
58
|
7
|
|
|
|
|
10
|
($return)= eval { CORE::require($file) }; |
|
7
|
|
|
|
|
3852
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# something wrong, cleanup and bail out |
62
|
33
|
100
|
|
|
|
927
|
if ($@) { |
63
|
1
|
|
|
|
|
7
|
$@ =~ s#(?: in require)? at /?(?:\w+/)*as\.pm line \d+.\s+##s; |
64
|
1
|
|
|
|
|
76
|
croak $@; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# not requiring a module, we're done |
68
|
32
|
|
|
|
|
52
|
my $module= shift; |
69
|
32
|
100
|
|
|
|
137
|
return $return if $module !~ s#\.pm$##; |
70
|
30
|
|
|
|
|
54
|
$module =~ s#/#::#g; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# there's an "import" already, embed it |
73
|
30
|
100
|
|
|
|
196
|
if ( my $import= $module->can('import') ) { |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# install our own importer |
76
|
29
|
|
|
|
|
147
|
*{ $module . '::import' }= sub { |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# we need to do aliasing: do it and remove them params |
79
|
39
|
100
|
100
|
39
|
|
319
|
if ( @_ >= 3 and $_[-2] eq 'as' ) { |
80
|
4
|
|
|
|
|
9
|
my ( undef, $alias )= splice @_, -2; |
81
|
4
|
|
|
|
|
7
|
_alias( $module, $alias ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# hopefully keep same scope as caller |
85
|
37
|
50
|
|
|
|
2162
|
goto &$import if @_; |
86
|
29
|
|
|
|
|
108
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# no import to embed, simply install our own |
91
|
|
|
|
|
|
|
else { |
92
|
1
|
|
|
|
|
3
|
*{ $module . '::import' }= \&_import; |
|
1
|
|
|
|
|
4
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# really done now |
96
|
30
|
|
|
|
|
96
|
return $return; |
97
|
1
|
|
|
|
|
47
|
}; |
98
|
|
|
|
|
|
|
} #BEGIN |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# satisfy -require- |
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
104
|
|
|
|
|
|
|
# |
105
|
|
|
|
|
|
|
# Internal subroutines |
106
|
|
|
|
|
|
|
# |
107
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
108
|
|
|
|
|
|
|
# _alias |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# Perform the actual stash aliasing |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# IN: 1 original class name |
113
|
|
|
|
|
|
|
# 2 alias class name |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _alias { |
116
|
4
|
|
|
4
|
|
7
|
my ( $module, $alias )= @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# allow dirty stuff happening without anyone complaining about it |
119
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
212
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# make sure we're not treading on already taken territory |
122
|
4
|
100
|
|
|
|
4
|
if ( %{ $alias . '::' } ) { |
|
4
|
|
|
|
|
10
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# alias already used, bail out if not same |
125
|
3
|
100
|
|
|
|
9
|
if ( my $old= $ALIASED{$alias} ) { |
126
|
2
|
100
|
|
|
|
87
|
croak |
127
|
|
|
|
|
|
|
"Cannot alias '$alias' to '$module': already aliased to '$old'" |
128
|
|
|
|
|
|
|
if $old ne $module; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# not aliased yet, but, but, but... |
132
|
|
|
|
|
|
|
else { |
133
|
1
|
|
|
|
|
160
|
croak "Cannot alias '$alias' to '$module': already taken"; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# perform the actual stash aliasing and remember it |
138
|
2
|
|
|
|
|
2
|
*{ $alias . '::' }= *{ $module . '::' }; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
4
|
|
139
|
2
|
|
|
|
|
7
|
$ALIASED{$alias}= $module; |
140
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
6
|
s#::#/#g foreach ( $module, $alias ); |
142
|
2
|
|
|
|
|
7
|
$INC{"$alias.pm"}= $INC{"$module.pm"}; |
143
|
|
|
|
|
|
|
|
144
|
2
|
|
|
|
|
3
|
return; |
145
|
|
|
|
|
|
|
} #_alias |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
148
|
|
|
|
|
|
|
# _import |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# Generic importer, same for all modules that didn't have an import yet |
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
# IN: 1 class |
153
|
|
|
|
|
|
|
# 2..N parameters |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub _import { |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# nothing to be done |
158
|
1
|
50
|
33
|
1
|
|
365
|
return if @_ < 3 or $_[-2] ne 'as'; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# perform the alias |
161
|
0
|
|
|
|
|
|
_alias( $_[0], $_[-1] ); |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return; |
164
|
|
|
|
|
|
|
} #_import |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__END__ |