line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl6::Export; |
2
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
my $ident = qr{ [^\W\d] \w* }x; |
5
|
|
|
|
|
|
|
my $arg = qr{ : $ident \s* ,? \s* }x; |
6
|
|
|
|
|
|
|
my $args = qr{ \s* \( $arg* \) | (?# NOTHING) }x; |
7
|
|
|
|
|
|
|
my $defargs = qr{ \s* \( $arg* :DEFAULT $arg* \) }x; |
8
|
|
|
|
|
|
|
my $proto = qr{ \s* (?: \( [^)]* \) | (?# NOTHING) ) }x; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub add_to { |
11
|
3
|
|
|
3
|
0
|
9
|
my ($EXPORT, $symbol, $args, $decl) = @_; |
12
|
3
|
100
|
|
|
|
11
|
$args = "()" unless $args =~ /\S/; |
13
|
3
|
|
|
|
|
8
|
$args =~ tr/://d; |
14
|
3
|
|
|
|
|
28
|
return qq[BEGIN{no strict 'refs';] |
15
|
|
|
|
|
|
|
. qq[push\@$EXPORT,'$symbol';\$EXPORT{'$symbol'}=1;] |
16
|
|
|
|
|
|
|
. qq[push\@{\$EXPORT_TAGS\{\$_}},'$symbol' for ('ALL',qw$args)}$decl]; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub false_import_sub { |
20
|
1
|
|
|
1
|
0
|
2
|
my $import_sub = q{ |
21
|
|
|
|
|
|
|
use base 'Exporter'; |
22
|
|
|
|
|
|
|
sub import { |
23
|
|
|
|
|
|
|
my @exports; |
24
|
|
|
|
|
|
|
for (my $i=1; $i<@_; $i++) { |
25
|
|
|
|
|
|
|
for ($_[$i]) { |
26
|
|
|
|
|
|
|
if (!ref && /^[:\$&%\@]?(\w+)$/ && |
27
|
|
|
|
|
|
|
( exists $EXPORT{$1} || exists $EXPORT_TAGS{$1}) ) { |
28
|
|
|
|
|
|
|
push @exports, splice @_, $i, 1; |
29
|
|
|
|
|
|
|
$i--; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
@exports = ":DEFAULT" unless @exports; |
34
|
|
|
|
|
|
|
__PACKAGE__->export_to_level(1, $_[0], ':MANDATORY', @exports); |
35
|
|
|
|
|
|
|
goto &REAL_IMPORT; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
}; |
38
|
1
|
|
|
|
|
13
|
$import_sub =~ s/\n/ /g; |
39
|
1
|
|
|
|
|
8
|
$import_sub =~ s/REAL_IMPORT/$_[0]/g; |
40
|
1
|
|
|
|
|
5
|
return $import_sub; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $MANDATORY = q[BEGIN{$EXPORT_TAGS{MANDATORY}||=[]}]; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
28247
|
use Filter::Simple; |
|
1
|
|
|
|
|
32885
|
|
|
1
|
|
|
|
|
8
|
|
46
|
1
|
|
|
1
|
|
63
|
use Digest::MD5 'md5_hex'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
400
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
FILTER { |
49
|
|
|
|
|
|
|
return unless /\S/; |
50
|
|
|
|
|
|
|
my $real_import_name = '_import_'.md5_hex($_); |
51
|
|
|
|
|
|
|
my $false_import_sub = false_import_sub($real_import_name); |
52
|
|
|
|
|
|
|
my $real_import_sub = ""; |
53
|
|
|
|
|
|
|
s/ \b sub \s+ import \s* ([({]) /sub $real_import_name$1/x |
54
|
|
|
|
|
|
|
or $real_import_sub = "sub $real_import_name {}"; |
55
|
|
|
|
|
|
|
s{( \b sub \s+ ($ident) $proto) \s+ is \s+ export ($defargs) } |
56
|
|
|
|
|
|
|
{ add_to('EXPORT',$2,$3,$1) }gex; |
57
|
|
|
|
|
|
|
s{( \b our \s+ ([\$\@\%]$ident) $proto) \s+ is \s+ exported ($defargs) } |
58
|
|
|
|
|
|
|
{ add_to('EXPORT',$2,$3,$1) }gex; |
59
|
|
|
|
|
|
|
s{( \b sub \s+ ($ident) $proto ) \s+ is \s+ export ($args) } |
60
|
|
|
|
|
|
|
{ add_to('EXPORT_OK',$2,$3,$1) }gex; |
61
|
|
|
|
|
|
|
s{( \b our \s+ ([\$\@\%]$ident) ) \s+ is \s+ export ($args) } |
62
|
|
|
|
|
|
|
{ add_to('EXPORT_OK',$2,$3,$1) }gex; |
63
|
|
|
|
|
|
|
$_ = $real_import_sub . $false_import_sub . $MANDATORY . $_; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |