File Coverage

blib/lib/Sentry/SourceFileRegistry/ContextLine.pm
Criterion Covered Total %
statement 37 37 100.0
branch 8 8 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 51 52 98.0


line stmt bran cond sub pod time code
1             use Mojo::Base -base, -signatures;
2 5     5   163511  
  5         18  
  5         28  
3             use List::Util qw(min max uniq);
4 5     5   3716 use Mojo::Util 'dumper';
  5         11  
  5         326  
5 5     5   30  
  5         9  
  5         2084  
6             has content => undef;
7             has line_count => 5;
8             has _lines => sub ($self) { [split(/\n/, $self->content)] };
9              
10             return [] if $line < 0;
11 8     8   1225 my $lower_bound = max(0, $line - $self->line_count);
  8         12  
  8         11  
  8         10  
12 8 100       21 my $from = $lower_bound - 1;
13 7         18 my $to = $line - 2;
14 7         36  
15 7         9 return [] if $to < 0;
16              
17 7 100       19 my @line_range = uniq(map { $_ >= 0 ? $_ : 0 } ($from .. $to));
18             return [grep {defined} @{ $self->_lines }[@line_range]];
19 5 100       11 }
  10         37  
20 5         11  
  9         66  
  5         11  
21             return [] if $line < 0;
22             my $upper_bound = min($line + $self->line_count, scalar $self->_lines->@*);
23 6     6   2091 return [@{ $self->_lines }[$line .. $upper_bound - 1]];
  6         9  
  6         6  
  6         7  
24 6 100       15 }
25 5         12  
26 5         39 my $line_count = $self->line_count;
  5         8  
27             return {
28             pre_context => $self->_get_lower_bound($line),
29 1     1 0 759 context_line => $self->_lines->[$line - 1],
  1         2  
  1         2  
  1         1  
30 1         3 post_context => $self->_get_upper_bound($line),
31             };
32 1         6 }
33              
34             1;