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   176726  
  5         18  
  5         28  
3             use List::Util qw(min max uniq);
4 5     5   4091 use Mojo::Util 'dumper';
  5         10  
  5         342  
5 5     5   29  
  5         15  
  5         2132  
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   1373 my $lower_bound = max(0, $line - $self->line_count);
  8         10  
  8         12  
  8         11  
12 8 100       25 my $from = $lower_bound - 1;
13 7         19 my $to = $line - 2;
14 7         42  
15 7         10 return [] if $to < 0;
16              
17 7 100       20 my @line_range = uniq(map { $_ >= 0 ? $_ : 0 } ($from .. $to));
18             return [grep {defined} @{ $self->_lines }[@line_range]];
19 5 100       12 }
  10         44  
20 5         13  
  9         71  
  5         11  
21             return [] if $line < 0;
22             my $upper_bound = min($line + $self->line_count, scalar $self->_lines->@*);
23 6     6   2208 return [@{ $self->_lines }[$line .. $upper_bound - 1]];
  6         12  
  6         7  
  6         8  
24 6 100       17 }
25 5         12  
26 5         42 my $line_count = $self->line_count;
  5         8  
27             return {
28             pre_context => $self->_get_lower_bound($line),
29 1     1 0 848 context_line => $self->_lines->[$line - 1],
  1         4  
  1         3  
  1         1  
30 1         5 post_context => $self->_get_upper_bound($line),
31             };
32 1         8 }
33              
34             1;