Otherwise, demands that a library file be included if it hasn't already
been included. The file is included via the do-FILE mechanism, which is
-essentially just a variety of C<eval>. Has semantics similar to the following
-subroutine:
+essentially just a variety of C<eval>. Has semantics similar to the
+following subroutine:
sub require {
- my($filename) = @_;
- return 1 if $INC{$filename};
- my($realfilename,$result);
- ITER: {
- foreach $prefix (@INC) {
- $realfilename = "$prefix/$filename";
- if (-f $realfilename) {
- $INC{$filename} = $realfilename;
- $result = do $realfilename;
- last ITER;
- }
- }
- die "Can't find $filename in \@INC";
- }
- delete $INC{$filename} if $@ || !$result;
- die $@ if $@;
- die "$filename did not return true value" unless $result;
- return $result;
+ my ($filename) = @_;
+ if (exists $INC{$filename}) {
+ return 1 if $INC{$filename};
+ die "Compilation failed in require";
+ }
+ my ($realfilename,$result);
+ ITER: {
+ foreach $prefix (@INC) {
+ $realfilename = "$prefix/$filename";
+ if (-f $realfilename) {
+ $INC{$filename} = $realfilename;
+ $result = do $realfilename;
+ last ITER;
+ }
+ }
+ die "Can't find $filename in \@INC";
+ }
+ if ($@) {
+ $INC{$filename} = undef;
+ die $@;
+ } elsif (!$result) {
+ delete $INC{$filename};
+ die "$filename did not return true value";
+ } else {
+ return $result;
+ }
}
Note that the file will not be included twice under the same specified