Atompub/MediaType.pm

filter: Statementstmt 100% 56 / 56 Branchbran 83.3% 20 / 24 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 17 / 17 Podpod 100% 9 / 9 totaltotal 92.2% 107 / 116 CC 15 SCAR 14.8
CC
15
Cov
93%
is_a
10.0
extensions
3.1
new
3.1
CRAP 4.4
« Atompub/Util.pm ↑ Summary Atompub.pm »
1 package Atompub::MediaType;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Atompub;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use MIME::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Perl6::Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 my %ATOM_TYPE = (
13 entry => 'application/atom+xml;type=entry',
14 feed => 'application/atom+xml;type=feed',
15 service => 'application/atomsvc+xml',
16 categories => 'application/atomcat+xml',
17 );
18  
19 6 __PACKAGE__->mk_accessors(qw(type subtype parameters));
20  
21 6 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 q{""} => \&as_string,
23 eq => \&is_a,
24 ne => \&is_not_a,
25 fallback => 1,
26 6 );
27  
28 71 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod documented
29 71 my($class, $arg) = @_;
30 71 ▶ my $media_type = $ATOM_TYPE{$arg} || $arg or return;
Branch: 1 branch
BranchTrueFalseTotal
my $media_type = $ATOM_TYPE{$arg} || $arg or return 71 0 71
Condition66%2/3
$ATOM_TYPE{$arg} || $arg
l!l&&r!l&&!r
11600
MC/DC0%0/2
$ATOM_TYPE{$arg} || $arg
$ATOM_TYPE{$arg} $arg
Truth table66%2/3
A || B
A= $ATOM_TYPE{$arg}B= $arg
ABresult
1X1
011
000
31 71 my($type, $subtype, $param) = split m{[/;]}, $media_type;
32 71 bless {
33 type => $type,
34 subtype => $subtype,
35 parameters => $param,
36 }, $class;
37 }
38  
39 6 ▶sub media_type :Export { __PACKAGE__->new(@_) }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine media_type: called CC=1 SCAR=0.0
Pod documented
40  
41 43 ▶sub subtype_major {
Subroutine subtype_major: called CC=2 SCAR=6.9
Pod documented
42 43 my($self) = @_;
43 43 ▶ $self->subtype =~ /\+(.+)/ ? $1 : $self->subtype;
Branch: 1 branch
BranchTrueFalseTotal
$self->subtype =~ /\+(.+)/ ? : 9 34 43
44 }
45  
46 44 ▶sub without_parameters {
Subroutine without_parameters: called CC=1 SCAR=0.0
Pod documented
47 44 my($self) = @_;
48 44 join '/', $self->type, $self->subtype;
49 }
50  
51 38 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
52 38 my($self) = @_;
53 38 join ';', grep { defined $_ } $self->without_parameters, $self->parameters;
54 }
55  
56 4 ▶sub extensions {
Subroutine extensions: called CC=3 SCAR=11.4
Pod documented
57 4 my($self) = @_;
58 4 ▶ my $mime = MIME::Types->new->type($self->without_parameters) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mime = "MIME::Types"->new->type($self->without_parameters) or return 4 0 4
59 4 my @exts = $mime->extensions;
60 4 ▶ wantarray ? @exts : $exts[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
61 }
62  
63 2 ▶sub extension { scalar shift->extensions }
Subroutine extension: called CC=1 SCAR=0.0
Pod documented
64  
65 39 ▶sub is_a {
Subroutine is_a: called CC=10 SCAR=23.1
Pod documented
66 39 my($self, $test) = @_;
67 39 ▶ $test = __PACKAGE__->new($test) unless UNIVERSAL::isa($test, __PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($test, __PACKAGE__) 37 2 39
68 39 ▶ return 1 if $test->type eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $test->type eq "*" 4 35 39
69 35 ▶ return 0 unless $test->type eq $self->type;
Branch: 1 branch
BranchTrueFalseTotal
unless $test->type eq $self->type 15 20 35
70 20 ▶ return 1 if $test->subtype eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $test->subtype eq "*" 3 17 20
71 17 ▶ if ($test->subtype eq $test->subtype_major) { # ex. application/xml
Branch: 1 branch
BranchTrueFalseTotal
if ($test->subtype eq $test->subtype_major) { } 12 5 17
72 12 ▶ return 0 unless $test->subtype_major eq $self->subtype_major;
Branch: 1 branch
BranchTrueFalseTotal
unless $test->subtype_major eq $self->subtype_major 6 6 12
73 }
74 else { # ex. application/atom+xml
75 5 ▶ return 0 unless $test->subtype eq $self->subtype;
Branch: 1 branch
BranchTrueFalseTotal
unless $test->subtype eq $self->subtype 0 5 5
76 }
77 11 ▶ return 1 if ! $test->parameters || ! $self->parameters;
Branch: 1 branch
BranchTrueFalseTotal
unless $test->parameters and $self->parameters 7 4 11
Condition66%2/3
$test->parameters and $self->parameters
!ll&&!rl&&r
704
MC/DC50%1/2
$test->parameters and $self->parameters
$test->parameters $self->parameters
Truth table66%2/3
A and B
A= $test->parametersB= $self->parameters
ABresult
0X0
100
111
78 4 return $test->parameters eq $self->parameters;
79 }
80  
81 7 ▶sub is_not_a {
Subroutine is_not_a: called CC=1 SCAR=0.0
Pod documented
82 7 my($self, @args) = @_;
83 7 !$self->is_a(@args);
84 }
85  
86 6 1;
87 __END__
« Atompub/Util.pm ↑ Summary Atompub.pm »