blib/lib/CPAN/Changes/HasEntries.pm

filter: Statementstmt 89.3% 59 / 66 Branchbran 50.0% 6 / 12 Conditioncond 42.8% 6 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 5 totaltotal 70.9% 83 / 117 CC 15 SCAR 18.1
CC
15
Cov
77%
remove_entry
20.0
__ANON__
7.2
add_entry
3.0
CRAP 6.1
« blib/lib/Test/CPAN/Changes.pm ↑ Summary blib/lib/CPAN/Changes.pm »
1 package CPAN::Changes::HasEntries;
2 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 32 our $VERSION = '0.500002';
6 32 $VERSION =~ tr/_//d;
7  
8 32 ▶use Sub::Quote qw(qsub);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use Types::Standard qw(ArrayRef InstanceOf Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 32 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 32 my $entry_type = (InstanceOf['CPAN::Changes::Entry'])->plus_coercions(
14 Str ,=> qsub q{ CPAN::Changes::Entry->new(text => $_[0]) },
15 );
16  
17 has entries => (
18 is => 'rw',
19 1220 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 32 isa => ArrayRef[$entry_type],
21 coerce => 1,
22 );
23  
24 sub clone {
25 15 ▶ my $self = shift;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
26 15 my %attrs = %$self;
27 15 $attrs{entries} = [ map $_->clone, @{$self->entries} ];
28 15 (ref $self)->new(%attrs, @_);
29 }
30  
31 sub has_entries {
32 151 ▶ my $self = shift;
Subroutine has_entries: called CC=2 SCAR=7.0
Pod undocumented
33 151 ▶ !!($self->entries && @{$self->entries});
Condition66%2/3
$self->entries && @{$self->entries;}
!ll&&!rl&&r
08962
MC/DC50%1/2
$self->entries && @{$self->entries;}
$self->entries @{$self->entries;}
Truth table66%2/3
A && B
A= $self->entriesB= @{$self->entries;}
ABresult
0X0
100
111
34 }
35  
36 sub find_entry {
37 2 ▶ my ($self, $find) = @_;
Subroutine find_entry: called CC=3 SCAR=11.0
Pod undocumented
38 return undef
39 2 ▶ unless $self->has_entries;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_entries 0 2 2
40 2 ▶ if (ref $find ne 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $find ne "Regexp") 1 1 2
41 1 $find = qr/\A\Q$find\E\z/;
42 }
43 2 my ($entry) = grep { $_->text =~ $find } @{ $self->entries };
44 2 return $entry;
45 }
46  
47 around serialize => sub {
48 83 ▶ my ($orig, $self, %args) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.7
49 83 ▶ my $indents = $args{indents} || [];
Condition50%1/2
$args{'indents'} || []
l!l
830
MC/DC0%0/1
$args{'indents'} || []
$args{'indents'}
Truth table50%1/2
A
A= $args{'indents'}
Aresult
11
00
50 83 ▶ my $styles = $args{styles} || [];
Condition50%1/2
$args{'styles'} || []
l!l
830
MC/DC0%0/1
$args{'styles'} || []
$args{'styles'}
Truth table50%1/2
A
A= $args{'styles'}
Aresult
11
00
51 83 ▶ my $width = $args{width} || 75;
Condition50%1/2
$args{'width'} || 75
l!l
830
MC/DC0%0/1
$args{'width'} || 75
$args{'width'}
Truth table50%1/2
A
A= $args{'width'}
Aresult
11
00
52 83 $indents = [ @{$indents}[1 .. $#$indents], ' '],
53 83 $styles = [ @{$styles}[1 .. $#$styles], '-'],
54 my $out = $self->$orig(@_);
55 83 ▶ my $entries = $self->entries || [];
Condition50%1/2
$self->entries || []
l!l
830
MC/DC0%0/1
$self->entries || []
$self->entries
Truth table50%1/2
A
A= $self->entries
Aresult
11
00
56 83 for my $entry ( @$entries ) {
57 62 my $sub = $entry->serialize(
58 indents => $indents,
59 styles => $styles,
60 width => $width - length $indents->[0],
61 );
62 62 $sub =~ s/^(.)/$indents->[0]$1/mg;
63 62 ▶ $sub .= "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $entry->has_entries 18 44 62
64 if $entry->has_entries;
65 62 $out .= $sub;
66 }
67 83 $out =~ s/\n\n+\z/\n/;
68 83 return $out;
69 32 };
70  
71 sub add_entry {
72 7 ▶ my ($self, @entries) = @_;
Subroutine add_entry: called CC=3 SCAR=11.1
Pod undocumented
73 $_ = $entry_type->coerce($_)
74 7 for @entries;
75 7 push @{ $self->entries }, @entries;
76 7 ▶ return wantarray ? @entries : $entries[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
77 }
78  
79 sub remove_entry {
80 0 ▶ my ($self, $entry) = @_;
Subroutine remove_entry: not called CC=4 SCAR=30.0
Pod undocumented
81 0 ▶ $entry
Branch: 1 branch
BranchTrueFalseTotal
ref $entry && $entry->isa('CPAN::Changes::Entry') ? : 0 0 0
Condition0%0/3
ref $entry and $entry->isa("CPAN::Changes::Entry")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $entry and $entry->isa("CPAN::Changes::Entry")
ref $entry $entry->isa("CPAN::Changes::Entry")
Truth table0%0/3
A and B
A= ref $entryB= $entry->isa("CPAN::Changes::Entry")
ABresult
0X0
100
111
82 = ref $entry && $entry->isa('CPAN::Changes::Entry') ? $entry
83 : $self->find_entry($entry);
84 0 ▶ return unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
85 0 my @entries = grep { $_ != $entry } @{ $self->entries };
86 0 $self->entries(\@entries);
87 }
88  
89 32 require CPAN::Changes::Entry;
90 32 1;
« blib/lib/Test/CPAN/Changes.pm ↑ Summary blib/lib/CPAN/Changes.pm »