Atompub/Util.pm

filter: Statementstmt 100% 52 / 52 Branchbran 87.5% 14 / 16 Conditioncond 83.3% 15 / 18 MC/DCmcdc 70.0% 7 / 10 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 92.6% 101 / 109 CC 17 SCAR 18.9
CC
17
Cov
94%
is_allowed_category
12.1
_match_category
4.0
is_acceptable_media_type
3.0
CRAP 6.6
« Atompub/DateTime.pm ↑ Summary Atompub/MediaType.pm »
1 package Atompub::Util;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Atompub;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Atompub::MediaType qw(media_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Perl6::Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use XML::Atom::Category;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 ▶sub is_acceptable_media_type :Export {
Subroutine is_acceptable_media_type: called CC=3 SCAR=11.0
Pod documented
12 14 my($coll, $content_type) = @_;
13  
14 14 ▶ return 1 unless $coll;
Branch: 1 branch
BranchTrueFalseTotal
unless $coll 0 14 14
15  
16 14 my @accepts = map { split /[\s,]+/ } $coll->accept;
17 14 ▶ @accepts = (media_type('entry')) unless @accepts; # assign default type
Branch: 1 branch
BranchTrueFalseTotal
unless @accepts 2 12 14
18  
19 14 grep { media_type($content_type)->is_a($_) } @accepts;
20 5 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 ▶sub is_allowed_category :Export {
Subroutine is_allowed_category: called CC=12 SCAR=24.9
Pod documented
23 11 my($coll, @tests) = @_;
24  
25 11 ▶ return 1 unless $coll;
Branch: 1 branch
BranchTrueFalseTotal
unless $coll 0 11 11
26 11 ▶ return 1 unless $coll->categories;
Branch: 1 branch
BranchTrueFalseTotal
unless $coll->categories 1 10 11
27  
28 10 ▶ return 1 if grep { ! $_->fixed || $_->fixed ne 'yes' } $coll->categories;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $_->fixed or $_->fixed ne "yes";} $coll->categories 1 9 10
Condition66%2/3
!$_->fixed || $_->fixed ne 'yes'
l!l&&r!l&&!r
109
MC/DC50%1/2
!$_->fixed || $_->fixed ne 'yes'
!$_->fixed $_->fixed ne 'yes'
Truth table66%2/3
not(A) || B
A= !$_->fixedB= $_->fixed ne 'yes'
ABresult
1X1
011
000
29  
30 9 my @allowed;
31 9 for my $cats ($coll->categories) {
32 9 push @allowed, map { my $cat = XML::Atom::Category->new;
33 9 ▶ my $scheme = $_->scheme || $cats->scheme;
Condition100%3/3
$_->scheme || $cats->scheme
l!l&&r!l&&!r
225
MC/DC100%2/2
$_->scheme || $cats->scheme
$_->scheme $cats->scheme
Truth table100%3/3
A || B
A= $_->schemeB= $cats->scheme
ABresult
1X1
011
000
34 9 $cat->term($_->term);
35 9 ▶ $cat->scheme($scheme) if $scheme;
Branch: 1 branch
BranchTrueFalseTotal
if $scheme 4 5 9
36 9 $cat }
37 $cats->category;
38 }
39  
40 9 ▶ return 0 if ! @allowed && @tests;
Branch: 1 branch
BranchTrueFalseTotal
if not @allowed and @tests 1 8 9
Condition66%2/3
not @allowed and @tests
!ll&&!rl&&r
801
MC/DC50%1/2
not @allowed and @tests
not @allowed @tests
Truth table66%2/3
not(A) and B
A= not @allowedB= @tests
ABresult
0X0
100
111
41  
42 8 for my $t (@tests) {
43 10 ▶ return 0 unless grep { _match_category($_, $t) } @allowed;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {_match_category($_, $t);} @allowed 3 7 10
44 }
45  
46 5 1;
47 5 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 12 ▶sub _match_category {
Subroutine _match_category: called CC=4 SCAR=13.9
50 12 my($allowed, $test) = @_;
51 12 ▶ return $allowed->term eq $test->term
Condition88%8/9
$allowed->term eq $test->term && (!$allowed->scheme || $test->scheme && $allowed->scheme eq $test->scheme)
!ll&&!rl&&r
327
not $allowed->scheme or $test->scheme and $allowed->scheme eq $test->scheme
l!l&&r!l&&!r
522
$test->scheme and $allowed->scheme eq $test->scheme
!ll&&!rl&&r
202
MC/DC75%3/4
$allowed->term eq $test->term && (!$allowed->scheme || $test->scheme && $allowed->scheme eq $test->scheme)
$allowed->term eq $test->term not $allowed->scheme $test->scheme $allowed->scheme eq $test->scheme
Truth table80%4/5
A && not(B) or C and D
A= $allowed->term eq $test->termB= not $allowed->schemeC= $test->schemeD= $allowed->scheme eq $test->scheme
ABCDresult
0XXX0
100X0
10100
11XX1
10111
52 && (!$allowed->scheme || $test->scheme && $allowed->scheme eq $test->scheme);
53 }
54  
55 5 1;
56 __END__
« Atompub/DateTime.pm ↑ Summary Atompub/MediaType.pm »