line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################################### |
2
|
|
|
|
|
|
|
# (c) makoto[at]cpan[dot]org and mixi perl community members |
3
|
|
|
|
|
|
|
# sample: |
4
|
|
|
|
|
|
|
# use delay_use; |
5
|
|
|
|
|
|
|
# $delay_use::DEBUG = 1;#実行時にエラーがあった場合STDERRに表示 |
6
|
|
|
|
|
|
|
# $delay_use::ABORT = 1;#実行時にエラーがあった場合プログラムを終了(exit-1)。 |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# ex1) |
9
|
|
|
|
|
|
|
# my $pkg = delay_use('CGI::Session') || delay_use( 'CGI' ) || die; |
10
|
|
|
|
|
|
|
# my $q = $pkg->new; |
11
|
|
|
|
|
|
|
# print $q->header; |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# ex2) |
14
|
|
|
|
|
|
|
# delay_use( 'CGI' ,qw/:standard/ ) or die($delay_use::ERROR); |
15
|
|
|
|
|
|
|
package delay_use; |
16
|
1
|
|
|
1
|
|
29485
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
17
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
18
|
1
|
|
|
1
|
|
6
|
use base qw(Exporter); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
323
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
20
|
|
|
|
|
|
|
our @EXPORT = qw(delay_use); |
21
|
|
|
|
|
|
|
our $ERROR = undef; |
22
|
|
|
|
|
|
|
our $DEBUG = 0; |
23
|
|
|
|
|
|
|
our $ABORT = 0; |
24
|
|
|
|
|
|
|
our %INC = (); |
25
|
|
|
|
|
|
|
sub delay_use { |
26
|
0
|
|
|
0
|
0
|
|
my $pkg = shift; |
27
|
0
|
|
0
|
|
|
|
my $caller = (caller)[0] || 'main'; |
28
|
0
|
|
0
|
|
|
|
my $func = $INC{$pkg} ||= eval qq{ |
29
|
|
|
|
|
|
|
sub { |
30
|
|
|
|
|
|
|
package $caller; |
31
|
|
|
|
|
|
|
eval qq{require $pkg}; |
32
|
|
|
|
|
|
|
if(\$@){ |
33
|
|
|
|
|
|
|
\$delay_use::ERROR = \$@; |
34
|
|
|
|
|
|
|
delete \$delay_use::INC{$pkg}; |
35
|
|
|
|
|
|
|
print STDERR \$delay_use::ERROR if \$delay_use::DEBUG; |
36
|
|
|
|
|
|
|
exit(-1) if \$delay_use::ABORT; |
37
|
|
|
|
|
|
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
$pkg->import(\@_) if $pkg->can('import'); |
40
|
|
|
|
|
|
|
return "$pkg"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
}; |
43
|
0
|
|
|
|
|
|
return $func->(@_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
__END__ |