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   171554  
  5         21  
  5         27  
3             use List::Util qw(min max uniq);
4 5     5   3869 use Mojo::Util 'dumper';
  5         10  
  5         353  
5 5     5   29  
  5         10  
  5         2119  
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   1372 my $lower_bound = max(0, $line - $self->line_count);
  8         11  
  8         12  
  8         11  
12 8 100       23 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       10 }
  10         40  
20 5         13  
  9         68  
  5         12  
21             return [] if $line < 0;
22             my $upper_bound = min($line + $self->line_count, scalar $self->_lines->@*);
23 6     6   2207 return [@{ $self->_lines }[$line .. $upper_bound - 1]];
  6         9  
  6         8  
  6         8  
24 6 100       17 }
25 5         13  
26 5         39 my $line_count = $self->line_count;
  5         9  
27             return {
28             pre_context => $self->_get_lower_bound($line),
29 1     1 0 775 context_line => $self->_lines->[$line - 1],
  1         3  
  1         2  
  1         2  
30 1         3 post_context => $self->_get_upper_bound($line),
31             };
32 1         7 }
33              
34             1;