-
-
Save anonymous/2d83c218d6d07ff742c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Loader.pm b/lib/Mojo/Loader.pm | |
index f1038fa..c9eb7de 100644 | |
--- a/lib/Mojo/Loader.pm | |
+++ b/lib/Mojo/Loader.pm | |
@@ -1,13 +1,17 @@ | |
package Mojo::Loader; | |
use Mojo::Base -base; | |
+use Fcntl ':flock'; | |
use File::Basename 'fileparse'; | |
use File::Spec::Functions qw(catdir catfile splitdir); | |
+use File::Temp 'tempfile'; | |
use Mojo::Exception; | |
use Mojo::Util qw(b64_decode class_to_path); | |
my (%BIN, %CACHE); | |
+my $LOCK = tempfile; | |
+ | |
sub data { $_[1] ? $_[2] ? _all($_[1])->{$_[2]} : _all($_[1]) : undef } | |
sub is_binary { keys %{_all($_[1])} ? !!$BIN{$_[1]}{$_[2]} : undef } | |
@@ -52,8 +56,10 @@ sub _all { | |
return $CACHE{$class} if $CACHE{$class}; | |
my $handle = do { no strict 'refs'; \*{"${class}::DATA"} }; | |
return {} unless fileno $handle; | |
+ flock $LOCK, LOCK_EX; | |
seek $handle, 0, 0; | |
my $data = join '', <$handle>; | |
+ flock $LOCK, LOCK_UN; | |
# Ignore everything before __DATA__ (Windows will seek to start of file) | |
$data =~ s/^.*\n__DATA__\r?\n/\n/s; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment