Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
documentation tweaks
  • Loading branch information
kraih committed Nov 12, 2012
1 parent 303e9bc commit 01df8cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@
- Improved error message accuracy in Mojo::Template by using line
directives.
- Improved performance of contains method in Mojo::Asset::File by 100%.
- Improved documentation.
- Improved tests.
- Fixed range bug in Mojo::Asset::Memory.

Expand Down
14 changes: 6 additions & 8 deletions lib/Mojo/Exception.pm
Expand Up @@ -92,32 +92,30 @@ sub _context {
}

sub _detect {
my $self = shift;
my ($self, $msg, $files) = @_;

# Message
my $msg = shift;
return $msg if blessed $msg && $msg->isa('Mojo::Exception');
$self->message($msg);

# Extract file and line from message
my @trace;
while ($msg =~ /at\s+(.+?)\s+line\s+(\d+)/g) { push @trace, [$1, $2] }
while ($msg =~ /at\s+(.+?)\s+line\s+(\d+)/g) { unshift @trace, [$1, $2] }

# Extract file and line from stacktrace
my $first = $self->frames->[0];
unshift @trace, [$first->[1], $first->[2]] if $first && $first->[1];
unshift @trace, [$first->[1], $first->[2]] if $first;

# Search for context in files
for my $frame (reverse @trace) {
for my $frame (@trace) {
next unless -r $frame->[0];
open my $handle, '<:utf8', $frame->[0];
$self->_context($frame->[1], [[<$handle>]]);
return $self;
}

# More context
return $self unless my $files = shift;
$self->_context($trace[0][1], [map { [split /\n/] } @$files]);
$self->_context($trace[0][1], [map { [split /\n/] } @$files]) if $files;

return $self;
}
Expand Down Expand Up @@ -213,7 +211,7 @@ Throw exception with stacktrace.
my $string = $e->to_string;
my $string = "$e";
Render exception with context.
Render exception.
=head2 C<trace>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -102,7 +102,7 @@ sub compile {

# Compile with line directive
return undef unless my $code = $self->code;
my $compiled = eval qq{#line 1 "@{[$self->name]}"\n} . $code;
my $compiled = eval qq{#line 1 "@{[$self->name]}"\n$code};
$self->compiled($compiled) and return undef unless $@;

# Use local stacktrace for compile exceptions
Expand Down

0 comments on commit 01df8cf

Please sign in to comment.