File Coverage

blib/lib/TAP/Formatter/GitHubActions/ErrorAggregate.pm
Criterion Covered Total %
statement 31 31 100.0
branch n/a
condition 2 3 66.6
subroutine 12 12 100.0
pod 3 3 100.0
total 48 49 97.9


line stmt bran cond sub pod time code
1             package TAP::Formatter::GitHubActions::ErrorAggregate;
2              
3 2     2   703 use strict;
  2         4  
  2         68  
4 2     2   9 use warnings;
  2         3  
  2         81  
5 2     2   21 use v5.16;
  2         16  
6 2     2   12 use base 'TAP::Object';
  2         7  
  2         228  
7 2     2   624 use TAP::Formatter::GitHubActions::ErrorGroup;
  2         6  
  2         120  
8              
9             my @ATTR;
10              
11             BEGIN {
12 2     2   8 @ATTR = qw(groups);
13 2         19 __PACKAGE__->mk_methods(@ATTR);
14             }
15              
16             sub _initialize {
17 7     7   239932 my ($self) = @_;
18 7         38 $self->{groups} = {};
19 7         24 return $self;
20             }
21              
22             sub _ensure_group_in_line {
23 40     40   94 my ($self, $line) = @_;
24 40   66     98 return $self->groups->{$line} //= (
25             TAP::Formatter::GitHubActions::ErrorGroup->new(line => $line)
26             );
27             }
28              
29             sub add {
30 22     22 1 773 my ($self, @errors) = @_;
31 22         84 $self->group($_->line)->add($_) for @errors;
32 22         61 return $self;
33             }
34              
35             sub group {
36 40     40 1 277 my ($self, $key) = @_;
37 40         90 return $self->_ensure_group_in_line($key);
38             }
39              
40             sub as_sorted_array {
41 5     5 1 29 my ($self) = @_;
42              
43 5         13 return map { $self->groups->{$_} } sort _by_lexical_sortable_numbers keys %{$self->groups};
  33         194  
  5         17  
44             }
45              
46             sub _by_lexical_sortable_numbers {
47 68     68   252 sprintf("%04d", $a) <=> sprintf("%04d", $b);
48             }
49              
50             1;
51             =head1 NAME
52              
53             TAP::Formatter::GitHubActions::ErrorAggregate - An aggregate of errrors.
54              
55             It groups C and makes it easier to
56             access groups and loop all of them in oder.
57              
58             =head1 METHODS
59              
60             =head2 add(@errors)
61              
62             Saves C<@errors> into a respective C.
63              
64             =head2 group($line)
65              
66             Get's C for a given C<$line>.
67              
68             =head2 as_sorted_array()
69              
70             Returns an array of C sorted by line.
71              
72             =cut