| 1 | package Sentry::SourceFileRegistry::ContextLine; | ||||||||||
| 2 | 1 | ▶ | use Mojo::Base -base, -signatures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use List::Util qw(min max uniq); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mojo::Util 'dumper'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | has content => undef; | |||||||||
| 8 | 1 | has line_count => 5; | |||||||||
| 9 | 3 | ▶ | has _lines => sub ($self) { [split(/\n/, $self->content)] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | ▶ | sub _get_lower_bound ($self, $line) { | |||||||||
|
Subroutine
_get_lower_bound: called CC=4 SCAR=13.9
| |||||||||||
| 12 | 8 | ▶ | return [] if $line < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 7 | my $lower_bound = max(0, $line - $self->line_count); | |||||||||
| 14 | 7 | my $from = $lower_bound - 1; | |||||||||
| 15 | 7 | my $to = $line - 2; | |||||||||
| 16 | |||||||||||
| 17 | 7 | ▶ | return [] if $to < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | my @line_range = uniq(map { $_ >= 0 ? $_ : 0 } ($from .. $to)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 5 | return [grep {defined} @{ $self->_lines }[@line_range]]; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | ▶ | sub _get_upper_bound ($self, $line) { | |||||||||
|
Subroutine
_get_upper_bound: called CC=2 SCAR=6.9
| |||||||||||
| 24 | 6 | ▶ | return [] if $line < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 5 | my $upper_bound = min($line + $self->line_count, scalar $self->_lines->@*); | |||||||||
| 26 | 5 | return [@{ $self->_lines }[$line .. $upper_bound - 1]]; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | ▶ | sub get ($self, $line) { | |||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 1 | my $line_count = $self->line_count; | |||||||||
| 31 | return { | ||||||||||
| 32 | 1 | pre_context => $self->_get_lower_bound($line), | |||||||||
| 33 | context_line => $self->_lines->[$line - 1], | ||||||||||
| 34 | post_context => $self->_get_upper_bound($line), | ||||||||||
| 35 | }; | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 1 | 1; | |||||||||