Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove filename attribute again
  • Loading branch information
kraih committed Feb 26, 2016
1 parent 2b4a100 commit 6808d61
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,6 +1,5 @@

6.49 2016-02-26
- Added filename attribute to Mojo::Exception.
- Added inspect method to Mojo::Exception.
- Improved check_box and radio_button helpers with support for "on" default
values.
Expand Down
27 changes: 10 additions & 17 deletions lib/Mojo/Exception.pm
Expand Up @@ -2,9 +2,9 @@ package Mojo::Exception;
use Mojo::Base -base;
use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;

has [qw(filename verbose)];
has [qw(frames line lines_before lines_after)] => sub { [] };
has message => 'Exception!';
has 'verbose';

sub inspect {
my ($self, @source) = @_;
Expand All @@ -20,7 +20,7 @@ sub inspect {
# Search for context in files
for my $frame (@trace) {
next unless -r $frame->[0] && open my $handle, '<:utf8', $frame->[0];
$self->filename($frame->[0])->_context($frame->[1], [[<$handle>]]);
$self->_context($frame->[1], [[<$handle>]]);
return $self;
}

Expand Down Expand Up @@ -61,26 +61,26 @@ sub _append {
}

sub _context {
my ($self, $num, $lines) = @_;
my ($self, $num, $sources) = @_;

# Line
return unless defined $lines->[0][$num - 1];
return unless defined $sources->[0][$num - 1];
$self->line([$num]);
_append($self->line, $_->[$num - 1]) for @$lines;
_append($self->line, $_->[$num - 1]) for @$sources;

# Before
for my $i (2 .. 6) {
last if ((my $previous = $num - $i) < 0);
unshift @{$self->lines_before}, [$previous + 1];
_append($self->lines_before->[0], $_->[$previous]) for @$lines;
_append($self->lines_before->[0], $_->[$previous]) for @$sources;
}

# After
for my $i (0 .. 4) {
next if ((my $next = $num + $i) < 0);
next unless defined $lines->[0][$next];
next unless defined $sources->[0][$next];
push @{$self->lines_after}, [$next + 1];
_append($self->lines_after->[-1], $_->[$next]) for @$lines;
_append($self->lines_after->[-1], $_->[$next]) for @$sources;
}
}

Expand Down Expand Up @@ -115,13 +115,6 @@ L<Mojo::Exception> is a container for exceptions with context information.
L<Mojo::Exception> implements the following attributes.
=head2 filename
my $name = $e->filename;
$e = $e->filename('test.pl');
The file where the exception occurred if available.
=head2 frames
my $frames = $e->frames;
Expand Down Expand Up @@ -178,8 +171,8 @@ following new ones.
$e = $e->inspect;
$e = $e->inspect($source1, $source2);
Inspect L</"message"> and L</"frames"> to fill L</"filename">,
L</"lines_before">, L</"line"> and L</"lines_after"> with context information.
Inspect L</"message"> and L</"frames"> to fill L</"lines_before">, L</"line">
and L</"lines_after"> with context information.
=head2 new
Expand Down
1 change: 0 additions & 1 deletion t/mojo/exception.t
Expand Up @@ -25,7 +25,6 @@ eval {
$e = $@;
isa_ok $e, 'Mojo::Exception', 'right class';
is $e, 'Works!', 'right result';
like $e->filename, qr/exception\.t/, 'right name';
like $e->frames->[0][1], qr/exception\.t/, 'right file';
is $e->lines_before->[0][0], 15, 'right number';
is $e->lines_before->[0][1], 'eval {', 'right line';
Expand Down
4 changes: 1 addition & 3 deletions t/mojo/template.t
Expand Up @@ -1091,8 +1091,7 @@ $mt = Mojo::Template->new;
$file = catfile dirname(__FILE__), 'templates', 'exception.mt';
$output = $mt->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/exception\.mt line 2/, 'message contains filename';
like $output->filename, qr/exception\.mt/, 'right name';
like $output->message, qr/exception\.mt line 2/, 'message contains filename';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->line->[0], 2, 'right number';
Expand All @@ -1107,7 +1106,6 @@ $output = $mt->name('"foo.mt" from DATA section')->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/foo\.mt from DATA section line 2/,
'message contains filename';
is $output->filename, undef, 'no name';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->line->[0], 2, 'right number';
Expand Down

0 comments on commit 6808d61

Please sign in to comment.