blib/lib/CPAN/Changes/Release.pm

filter: Statementstmt 82.9% 112 / 135 Branchbran 76.6% 23 / 30 Conditioncond 61.1% 22 / 36 MC/DCmcdc 33.3% 7 / 21 Subroutinesub 84.2% 16 / 19 Podpod 100% 12 / 12 totaltotal 75.8% 192 / 253 CC 34 SCAR 16.5
CC
34
Cov
78%
set_changes
20.0
serialize
6.3
delete_group
6.0
CRAP 5.2
« blib/lib/CPAN/Changes/HasEntries.pm ↑ Summary blib/lib/CPAN/Changes/Entry.pm »
1 package CPAN::Changes::Release;
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.500005';
6 32 $VERSION =~ tr/_//d;
7  
8 32 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 32 with 'CPAN::Changes::HasEntries';
11  
12 32 has version => (is => 'rw');
13 32 has date => (is => 'rw');
14 32 has note => (is => 'rw');
15 32 has line => (is => 'ro');
16  
17 239 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=5 SCAR=17.1
18 239 my ($orig, $class, @args) = @_;
19 239 my $args = $class->$orig(@args);
20 239 ▶ if (my $changes = delete $args->{changes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $changes = delete $args->{"changes"}) 7 232 239
21 7 ▶ if ($args->{entries}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"entries"}) 0 7 7
22 0 die "Mixing back-compat interface with new interface not allowed";
23 }
24 7 $args->{entries} = [];
25 7 for my $group (sort keys %$changes) {
26 7 my @entries = @{$changes->{$group}};
27  
28 7 ▶ if ($group eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($group eq '') { } 7 0 7
29 7 push @{$args->{entries}}, @entries;
30 }
31 else {
32 0 my $entry = CPAN::Changes::Entry->new(
33 text => $group,
34 entries => \@entries,
35 );
36 0 push @{$args->{entries}}, $entry;
37 }
38 }
39 }
40 239 $args;
41 32 };
42  
43 21 ▶sub serialize {
Subroutine serialize: called CC=6 SCAR=18.4
Pod documented
44 21 my ($self, %args) = @_;
45 21 ▶ my $indents = $args{indents} || ['', ' ', ''];
Condition50%1/2
$args{'indents'} || ['', ' ', '']
l!l
210
MC/DC0%0/1
$args{'indents'} || ['', ' ', '']
$args{'indents'}
Truth table50%1/2
A
A= $args{'indents'}
Aresult
11
00
46 21 ▶ my $styles = $args{styles} || ['', '[]'];
Condition50%1/2
$args{'styles'} || ['', '[]']
l!l
210
MC/DC0%0/1
$args{'styles'} || ['', '[]']
$args{'styles'}
Truth table50%1/2
A
A= $args{'styles'}
Aresult
11
00
47 21 ▶ my $width = $args{width} || 75;
Condition50%1/2
$args{'width'} || 75
l!l
210
MC/DC0%0/1
$args{'width'} || 75
$args{'width'}
Truth table50%1/2
A
A= $args{'width'}
Aresult
11
00
48  
49 21 my $out = $indents->[0] . $styles->[0] . $self->version;
50 21 ▶ if ($self->date || $self->note) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->date or $self->note) 19 2 21
Condition66%2/3
$self->date or $self->note
l!l&&r!l&&!r
1902
MC/DC50%1/2
$self->date or $self->note
$self->date $self->note
Truth table66%2/3
A or B
A= $self->dateB= $self->note
ABresult
1X1
011
000
51 19 $out .= ' ' . join ' ', (grep { defined } $self->date, $self->note);
52 }
53 21 $out . "\n";
54 }
55  
56 21 ▶around serialize => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
57 21 my ($orig, $self, %args) = @_;
58 21 ▶ $args{indents} ||= ['', ' ', ''];
Condition100%2/2
$args{"indents"} ||= ["", " ", ""]
l!l
192
MC/DC100%1/1
$args{"indents"} ||= ["", " ", ""]
$args{"indents"}
Truth table100%2/2
A
A= $args{"indents"}
Aresult
11
00
59 21 ▶ $args{styles} ||= ['', '[]'];
Condition100%2/2
$args{"styles"} ||= ["", "[]"]
l!l
192
MC/DC100%1/1
$args{"styles"} ||= ["", "[]"]
$args{"styles"}
Truth table100%2/2
A
A= $args{"styles"}
Aresult
11
00
60 21 ▶ $args{width} ||= 75;
Condition100%2/2
$args{"width"} ||= 75
l!l
192
MC/DC100%1/1
$args{"width"} ||= 75
$args{"width"}
Truth table100%2/2
A
A= $args{"width"}
Aresult
11
00
61 21 ▶ if (my $sort = $args{group_sort}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sort = $args{"group_sort"}) 3 18 21
62 3 my $entries = $self->_sorted_groups($sort);
63 3 $self = $self->clone(entries => $entries);
64 }
65 21 $self->$orig(%args);
66 32 };
67  
68 35 ▶sub changes {
Subroutine changes: called CC=2 SCAR=6.9
Pod documented
69 35 my ($self, $group) = @_;
70 35 ▶ if (defined $group) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group) { } 15 20 35
71 15 return $self->get_group($group)->changes;
72 }
73 else {
74 20 return { map { $_ => $self->get_group($_)->changes } $self->groups };
75 }
76 }
77  
78 2 ▶sub add_changes {
Subroutine add_changes: called CC=4 SCAR=13.9
Pod documented
79 2 my $self = shift;
80 2 my %opts;
81 2 ▶ if (@_ > 1 && ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and ref $_[0] eq "HASH") 1 1 2
Condition66%2/3
@_ > 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
101
MC/DC50%1/2
@_ > 1 and ref $_[0] eq "HASH"
@_ > 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ > 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
82 1 %opts = %{ +shift };
83 }
84 2 ▶ $self->get_group($opts{group} || '')->add_changes(@_);
Condition100%2/2
$opts{'group'} || ''
l!l
11
MC/DC100%1/1
$opts{'group'} || ''
$opts{'group'}
Truth table100%2/2
A
A= $opts{'group'}
Aresult
11
00
85 }
86  
87 0 ▶sub set_changes {
Subroutine set_changes: not called CC=4 SCAR=30.0
Pod documented
88 0 my $self = shift;
89 0 my %opts;
90 0 ▶ if (@_ > 1 && ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and ref $_[0] eq "HASH") 0 0 0
Condition0%0/3
@_ > 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 1 and ref $_[0] eq "HASH"
@_ > 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ > 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
91 0 %opts = %{ +shift };
92 }
93 0 ▶ $self->get_group($opts{group} || '')->set_changes(@_);
Condition0%0/2
$opts{'group'} || ''
l!l
00
MC/DC0%0/1
$opts{'group'} || ''
$opts{'group'}
Truth table0%0/2
A
A= $opts{'group'}
Aresult
11
00
94 }
95  
96 1 ▶sub clear_changes {
Subroutine clear_changes: called CC=1 SCAR=0.0
Pod documented
97 1 $_[0]->entries([]);
98 }
99  
100 44 ▶sub groups {
Subroutine groups: called CC=4 SCAR=13.9
Pod documented
101 44 my ($self, %args) = @_;
102 44 ▶ my $sort = $args{sort} || sub { sort @_ };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$args{'sort'} || sub { sort @_; }
l!l&&r!l&&!r
1430
MC/DC0%0/2
$args{'sort'} || sub { sort @_; }
$args{'sort'} sub { sort @_; }
Truth table66%2/3
A || B
A= $args{'sort'}B= sub { sort @_; }
ABresult
1X1
011
000
103 44 my %groups;
104 44 for my $entry ( @{ $self->entries } ) {
105 46 ▶ if ($entry->has_entries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->has_entries) { } 13 33 46
106 13 $groups{$entry->text}++;
107 }
108 else {
109 33 $groups{''}++;
110 }
111 }
112 44 return $sort->(keys %groups);
113 }
114  
115 0 ▶sub add_group {
Subroutine add_group: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($self, @groups) = @_;
117 0 push @{ $self->entries }, map { CPAN::Changes::Entry->new(text => $_) } @groups;
118 }
119  
120 0 ▶sub delete_group {
Subroutine delete_group: not called CC=2 SCAR=17.9
Pod documented
121 0 my ($self, @groups) = @_;
122 0 my @entries = @{ $self->entries };
123 0 for my $name (@groups) {
124 0 @entries = grep { $_->text ne $name } @entries;
125 }
126 0 $self->entries(\@entries);
127 }
128  
129 # this is nonsense, but try to emulate. if nothing has entries, then there
130 # are no "groups", so leave everything.
131 4 ▶sub delete_empty_groups {
Subroutine delete_empty_groups: called CC=2 SCAR=6.9
Pod documented
132 4 my ($self) = @_;
133 4 my @entries = grep { $_->has_entries } @{ $self->entries };
134 return
135 4 ▶ if !@entries;
Branch: 1 branch
BranchTrueFalseTotal
unless @entries 1 3 4
136 3 $self->entries(\@entries);
137 }
138  
139 38 ▶sub get_group {
Subroutine get_group: called CC=4 SCAR=13.9
Pod documented
140 38 my ($self, $name) = @_;
141 38 require CPAN::Changes::Group;
142 38 ▶ if (defined $name && length $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) { } 6 32 38
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
0326
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
143 6 my ($entry) = grep { $_->text eq $name } @{ $self->entries };
144 6 ▶ $entry ||= $self->add_entry($name);
Condition66%2/3
$entry ||= $self->add_entry($name)
l!l&&r!l&&!r
510
MC/DC0%0/2
$entry ||= $self->add_entry($name)
$entry $self->add_entry($name)
Truth table66%2/3
A ||= B
A= $entryB= $self->add_entry($name)
ABresult
1X1
011
000
145 6 return CPAN::Changes::Group->new(_entry => $entry);
146 }
147 else {
148 32 return CPAN::Changes::Group->new(_entry => $self);
149 }
150 }
151  
152 2 ▶sub attach_group {
Subroutine attach_group: called CC=3 SCAR=11.2
Pod documented
153 2 my ($self, $group) = @_;
154 2 my $entry = $group->_maybe_entry;
155 2 my $text = $entry->text;
156 2 my $entries = $self->entries;
157 2 ▶ if ($text eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($text eq '') { } 0 2 2
elsif (my($found) = grep({$_->text eq $text;} @$entries)) { } 1 1 2
158 0 $self->add_entry( @{ $entry->entries } );
159 }
160 1 elsif (my ($found) = grep { $_->text eq $text } @$entries) {
161 1 $found->add_entry( @{ $entry->entries } );
162 }
163 else {
164 1 $self->add_entry( $entry );
165 }
166 }
167  
168 2 ▶sub group_values {
Subroutine group_values: called CC=1 SCAR=0.0
Pod documented
169 2 my ($self, @groups) = @_;
170 2 return map { $self->get_group($_) } $self->groups(@groups);
171 }
172  
173 3 ▶sub _sorted_groups {
Subroutine _sorted_groups: called CC=4 SCAR=14.0
174 3 my ($self, $sort_function) = @_;
175 3 my @groups = grep { $_->has_entries } @{ $self->entries };
176 3 my @bare = grep { !$_->has_entries } @{ $self->entries };
177 return \@bare
178 3 ▶ if !@groups;
Branch: 1 branch
BranchTrueFalseTotal
unless @groups 0 3 3
179  
180 3 my %entries = map { $_->text => [$_] } @groups;
181 3 ▶ $entries{''} = \@bare
Branch: 1 branch
BranchTrueFalseTotal
if @bare 0 3 3
182 if @bare;
183 3 my @sorted = $sort_function->(keys %entries);
184 3 ▶ return [ map { @{ $entries{$_} || [] } } @sorted ];
Condition50%1/2
$entries{$_} || []
l!l
60
MC/DC0%0/1
$entries{$_} || []
$entries{$_}
Truth table50%1/2
A
A= $entries{$_}
Aresult
11
00
185 }
186  
187 32 1;
188 __END__
« blib/lib/CPAN/Changes/HasEntries.pm ↑ Summary blib/lib/CPAN/Changes/Entry.pm »