| 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
Condition66%2/3
$ATOM_TYPE{$arg} || $arg
MC/DC0%0/2
$ATOM_TYPE{$arg} || $arg
$ATOM_TYPE{$arg}
$arg
Truth table66%2/3
A || B
A= $ATOM_TYPE{$arg}B= $arg
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | 4 | my @exts = $mime->extensions; | |||||||||||||||||||||||||||
| 60 | 4 | ▶ | wantarray ? @exts : $exts[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | 39 | ▶ | return 1 if $test->type eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 35 | ▶ | return 0 unless $test->type eq $self->type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 20 | ▶ | return 1 if $test->subtype eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 17 | ▶ | if ($test->subtype eq $test->subtype_major) { # ex. application/xml | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 12 | ▶ | return 0 unless $test->subtype_major eq $self->subtype_major; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else { # ex. application/atom+xml | ||||||||||||||||||||||||||||
| 75 | 5 | ▶ | return 0 unless $test->subtype eq $self->subtype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 11 | ▶ | return 1 if ! $test->parameters || ! $self->parameters; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$test->parameters and $self->parameters
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||