line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
1
|
|
|
1
|
|
445
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package filename v0.20.009; |
6
|
|
|
|
|
|
|
# ABSTRACT: Perl module to load files at compile-time, without BEGIN blocks. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp 1.50 (); |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
4
|
use File::Spec (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
429
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ( $do, $error ) = (); # Private subs |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Modified version of the code as specified in `perldoc -f require` |
16
|
|
|
|
|
|
|
*import = \&require; |
17
|
|
|
|
|
|
|
sub require { |
18
|
54
|
50
|
33
|
54
|
1
|
799360
|
eval { $_[0]->isa(__PACKAGE__) } && shift |
|
54
|
|
|
|
|
375
|
|
19
|
|
|
|
|
|
|
|| Carp::croak( $_[0], " is not a ", __PACKAGE__ ); |
20
|
54
|
100
|
|
|
|
146
|
my $filename = @_ ? shift : $_; |
21
|
54
|
50
|
|
|
|
98
|
Carp::croak("Null filename used") unless length($filename); |
22
|
|
|
|
|
|
|
|
23
|
54
|
100
|
|
|
|
259
|
return $INC{$filename} if ( exists $INC{$filename} ); |
24
|
|
|
|
|
|
|
|
25
|
39
|
100
|
|
|
|
268
|
if ( File::Spec->file_name_is_absolute($filename) ) { |
26
|
19
|
50
|
33
|
|
|
180
|
goto NOT_INC if $^V < v5.17.0 && !-r $filename; |
27
|
19
|
|
|
|
|
62
|
return $do->($filename); |
28
|
|
|
|
|
|
|
} |
29
|
20
|
|
|
|
|
37
|
foreach my $inc (@INC) { |
30
|
20
|
|
|
|
|
30
|
my $prefix = $inc; |
31
|
|
|
|
|
|
|
#if ( my $ref = ref($inc) ) { |
32
|
|
|
|
|
|
|
# # TODO ... |
33
|
|
|
|
|
|
|
#} |
34
|
20
|
50
|
|
|
|
344
|
next unless -f ( my $fullpath = "$prefix/$filename" ); |
35
|
20
|
50
|
33
|
|
|
216
|
next if $^V < v5.17.0 && !-r _; |
36
|
20
|
|
|
|
|
68
|
return $do->( $fullpath => $filename ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
NOT_INC: |
39
|
0
|
|
|
|
|
|
Carp::croak("Can't locate $filename in \@INC (\@INC contains: @INC)"); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $do_text = <<'END'; |
43
|
|
|
|
|
|
|
package $pkg; |
44
|
|
|
|
|
|
|
my $result = do($fullpath); |
45
|
|
|
|
|
|
|
die $@ if $@; |
46
|
|
|
|
|
|
|
$INC{$filename} = delete $INC{$fullpath} |
47
|
|
|
|
|
|
|
if $filename ne $fullpath && exists $INC{$fullpath}; |
48
|
|
|
|
|
|
|
$result; |
49
|
|
|
|
|
|
|
END |
50
|
|
|
|
|
|
|
$do = sub { |
51
|
|
|
|
|
|
|
my $fullpath = @_ ? shift : $_; |
52
|
|
|
|
|
|
|
my $filename = @_ ? shift : $fullpath; |
53
|
|
|
|
|
|
|
my ($pkg) = caller(2); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
( my $do_eval = $do_text ) =~ s/\$pkg/$pkg/; |
56
|
|
|
|
|
|
|
return eval $do_eval || $error->( $filename => $fullpath ); |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Private sub |
60
|
|
|
|
|
|
|
$error = sub { |
61
|
|
|
|
|
|
|
my $filename = @_ ? shift : $_; |
62
|
|
|
|
|
|
|
my $fullpath = @_ ? shift : $filename; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$INC{$filename} &&= undef($!); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$@ && Carp::croak( $@, "Compilation failed in require" ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$! && Carp::croak( |
69
|
|
|
|
|
|
|
"Can't locate $filename: ", |
70
|
|
|
|
|
|
|
$^V >= v5.21.0 ? "$fullpath: " : (), |
71
|
|
|
|
|
|
|
"$!" |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Carp::croak( $filename, " did not return a true value" ); |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |