VideoHost/Video.pm

filter: Statementstmt 52.6% 30 / 57 Branchbran 52.9% 18 / 34 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.7% 5 / 14 Podpod 18.1% 2 / 11 totaltotal 45.2% 57 / 126 CC 20 SCAR 23.2
CC
20
Cov
52%
metadata
20.0
check
17.4
path_to
6.1
CRAP 10.2
« VideoHost/Video/Storage.pm ↑ Summary VideoHost/Controller/Root.pm »
1 package App::VideoHost::Video;
2 {
3 2 $App::VideoHost::Video::VERSION = '0.143310'; # TRIAL
4 }
5  
6 # ABSTRACT: Encapsulate a single video
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 has 'directory' => (is => 'rw');
13  
14  
15 4 ▶sub check {
Subroutine check: called CC=11 SCAR=28.6
Pod documented
16 4 my $self = shift;
17  
18 # XXX there is room for a lot of optimisation here!
19  
20 4 ▶ die "no directory set\n" unless $self->directory;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->directory 0 4 4
21 4 ▶ die "directory does not exist\n" unless -d $self->directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->directory 1 3 4
22  
23 3 ▶ die "video does not exist\n" unless -f $self->path_to('video');
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->path_to("video") 1 2 3
24 2 ▶ die "video is empty\n" unless ! -z $self->path_to('video');
Branch: 1 branch
BranchTrueFalseTotal
if -z $self->path_to("video") 1 1 2
25  
26 1 ▶ die "poster exists but is empty\n" if (-e $self->path_to('poster') && -z $self->path_to('poster'));
Branch: 1 branch
BranchTrueFalseTotal
if -e $self->path_to("poster") and -z $self->path_to("poster") 0 1 1
Condition33%1/3
-e $self->path_to("poster") and -z $self->path_to("poster")
!ll&&!rl&&r
100
MC/DC0%0/2
-e $self->path_to("poster") and -z $self->path_to("poster")
-e $self->path_to("poster") -z $self->path_to("poster")
Truth table33%1/3
A and B
A= -e $self->path_to("poster")B= -z $self->path_to("poster")
ABresult
0X0
100
111
27  
28 1 ▶ die "tracks file exists but is empty\n" if (-e $self->path_to('tracks') && -z $self->path_to('tracks'));
Branch: 1 branch
BranchTrueFalseTotal
if -e $self->path_to("tracks") and -z $self->path_to("tracks") 0 1 1
Condition33%1/3
-e $self->path_to("tracks") and -z $self->path_to("tracks")
!ll&&!rl&&r
100
MC/DC0%0/2
-e $self->path_to("tracks") and -z $self->path_to("tracks")
-e $self->path_to("tracks") -z $self->path_to("tracks")
Truth table33%1/3
A and B
A= -e $self->path_to("tracks")B= -z $self->path_to("tracks")
ABresult
0X0
100
111
29  
30 1 ▶ die "metadata file does not exist\n" unless (-e $self->path_to('metadata'));
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->path_to("metadata") 1 0 1
31 0 ▶ die "metadata file is empty\n" if (-z $self->path_to('metadata'));
Branch: 1 branch
BranchTrueFalseTotal
if -z $self->path_to("metadata") 0 0 0
32  
33 0 return 1;
34 }
35  
36 0 ▶sub has_tracks { return -e shift->path_to('tracks') }
Subroutine has_tracks: not called CC=1 SCAR=6.9
Pod undocumented
37 0 ▶sub has_poster { return -e shift->path_to('poster') }
Subroutine has_poster: not called CC=1 SCAR=6.9
Pod undocumented
38  
39 0 ▶sub short_name { my $title = shift->metadata('title'); $title = lc($title); $title =~ s/\W/-/g; $title =~ s/\-+$//g; return $title };
Subroutine short_name: not called CC=1 SCAR=6.9
Pod undocumented
40 0 ▶sub id { shift->short_name }
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 0 ▶sub title { my $title = shift->metadata('title'); croak "no title" unless $title; return $title; }
Subroutine title: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $title 0 0 0
43  
44 0 ▶sub file { return shift->path_to('video') }
Subroutine file: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub poster { return shift->path_to('poster') }
Subroutine poster: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub tracks { return shift->path_to('tracks') }
Subroutine tracks: not called CC=1 SCAR=6.9
Pod undocumented
47  
48  
49 0 ▶sub metadata {
Subroutine metadata: not called CC=4 SCAR=30.0
Pod documented
50 0 my $self = shift;
51 0 my $key = shift;
52  
53 0 open my $fh, "<", $self->path_to('metadata');
54 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
55 0 chomp $line;
56 0 my ($k, $v) = ($line =~ /^(\w+)\s*:\s*(.*?)$/);
57 0 ▶ next unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
58 0 ▶ if ($k eq $key) { return $v }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq $key) 0 0 0
59 }
60 0 return;
61 }
62  
63 8 ▶sub path_to {
Subroutine path_to: called CC=6 SCAR=18.1
Pod undocumented
64 8 my $self = shift;
65 8 my $item = shift;
66 8 ▶ confess "what do you mean to look for the path to?" unless $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 8 8
67 8 my $dir = $self->directory;
68  
69 8 ▶ if ($item eq 'video') {
Branch: 4 branches
BranchTrueFalseTotal
if ($item eq 'video') { } 5 3 8
elsif ($item eq 'tracks') { } 1 2 3
elsif ($item eq 'poster') { } 1 1 2
elsif ($item eq 'metadata') { } 1 0 1
70 5 return File::Spec->catdir( $dir, 'video.mp4' );
71 }
72 elsif ($item eq 'tracks') {
73 1 return File::Spec->catdir( $dir, 'tracks.vtt' );
74 }
75 elsif ($item eq 'poster') {
76 1 return File::Spec->catdir( $dir, 'poster.jpg');
77 }
78 elsif ($item eq 'metadata') {
79 1 return File::Spec->catdir( $dir, 'metadata.txt');
80 }
81  
82 0 croak "do not know how to get path_to a $item";
83 }
84  
85 2 1;
86  
87 __END__
« VideoHost/Video/Storage.pm ↑ Summary VideoHost/Controller/Root.pm »