blib/lib/Sentry/SourceFileRegistry/ContextLine.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 97.8% 45 / 46 CC 5 SCAR 8.2
CC
5
Cov
100%
_get_lower_bound
4.0
_get_upper_bound
2.0
BEGIN
1.0
CRAP 2.3
« blib/lib/Sentry/Hub.pm ↑ Summary blib/lib/CGI/Application/Plugin/Sentry.pm »
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
BranchTrueFalseTotal
if $line < 0 1 7 8
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
BranchTrueFalseTotal
if $to < 0 2 5 7
18  
19 5 ▶ my @line_range = uniq(map { $_ >= 0 ? $_ : 0 } ($from .. $to));
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 ? : 9 1 10
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
BranchTrueFalseTotal
if $line < 0 1 5 6
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;
« blib/lib/Sentry/Hub.pm ↑ Summary blib/lib/CGI/Application/Plugin/Sentry.pm »