Plagger/Enclosure.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 63 CC 5 SCAR 17.1
CC
5
Cov
0%
auto_set_type
12.0
url
6.0
filename
6.0
CRAP 5.5
1 package Plagger::Enclosure;
2 use strict;
3  
4 use base qw( Class::Accessor::Fast );
5 __PACKAGE__->mk_accessors(qw( length type local_path is_inline ));
6  
7 use Plagger::Util;
8 use URI;
9  
10 sub url {
11 my $self = shift;
12 if (@_) {
13 $self->{url} = URI->new($_[0]);
14 }
15 $self->{url};
16 }
17  
18 sub auto_set_type {
19 my($self, $type) = @_;
20  
21 if (defined $type) {
22 return $self->type($type);
23 }
24  
25 # set MIME type via URL extension
26 my $mime = Plagger::Util::mime_type_of($self->url);
27 $self->type($mime->type) if $mime;
28 }
29  
30 sub media_type {
31 my $self = shift;
32 ( split '/', $self->type )[0] || 'unknown';
33 }
34  
35 sub sub_type {
36 my $self = shift;
37 ( split '/', $self->type )[1] || 'unknown';
38 }
39  
40 sub filename {
41 my $self = shift;
42 if (@_) {
43 $self->{filename} = shift;
44 }
45 $self->{filename} || (split '/', $self->url->path)[-1];
46 }
47  
48 1;
49