Skip to content

Commit

Permalink
fix bugs in Mojo::Loader and Mojo::Util where the DATA handle would b…
Browse files Browse the repository at this point in the history
…e mentioned in error messages (closes #989, closes #990)
  • Loading branch information
kraih committed Aug 16, 2016
1 parent 70c177d commit 6438593
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

7.02 2016-08-15
7.02 2016-08-16
- Fixed bugs in Mojo::Loader and Mojo::Util where the DATA handle would be
mentioned in error messages.

7.01 2016-08-01
- Improved support for systemd.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Loader.pm
Expand Up @@ -63,6 +63,7 @@ sub _all {
my $class = shift;

return $CACHE{$class} if $CACHE{$class};
local $.;
my $handle = do { no strict 'refs'; \*{"${class}::DATA"} };
return {} unless fileno $handle;
seek $handle, 0, 0;
Expand Down
9 changes: 6 additions & 3 deletions lib/Mojo/Util.pm
Expand Up @@ -32,9 +32,12 @@ use constant {
# To generate a new HTML entity table run this command
# perl examples/entities.pl
my %ENTITIES;
for my $line (split "\n", join('', <DATA>)) {
next unless $line =~ /^(\S+)\s+U\+(\S+)(?:\s+U\+(\S+))?/;
$ENTITIES{$1} = defined $3 ? (chr(hex $2) . chr(hex $3)) : chr(hex $2);
{
local $.;
for my $line (split "\n", join('', <DATA>)) {
next unless $line =~ /^(\S+)\s+U\+(\S+)(?:\s+U\+(\S+))?/;
$ENTITIES{$1} = defined $3 ? (chr(hex $2) . chr(hex $3)) : chr(hex $2);
}
}

# Characters that should be escaped in XML
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/loader.t
Expand Up @@ -160,4 +160,8 @@ is load_class('Mojolicious::Lite'), undef, 'loaded successfully';
['test.bin'], 'right DATA files';
}

# Hide DATA usage from error messages
eval "die 'whatever'";
unlike $@, qr/DATA/, 'DATA has been hidden';

done_testing();
4 changes: 4 additions & 0 deletions t/mojo/util.t
Expand Up @@ -500,4 +500,8 @@ is term_escape("\t\b\r\n\f"), "\\x09\\x08\\x0d\n\\x0c", 'right result';
is term_escape("\x00\x09\x0b\x1f\x7f\x80\x9f"), '\x00\x09\x0b\x1f\x7f\x80\x9f',
'right result';

# Hide DATA usage from error messages
eval "die 'whatever'";
unlike $@, qr/DATA/, 'DATA has been hidden';

done_testing();

0 comments on commit 6438593

Please sign in to comment.