| 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
| |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | die "directory does not exist\n" unless -d $self->directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | die "video does not exist\n" unless -f $self->path_to('video'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | die "video is empty\n" unless ! -z $self->path_to('video'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | die "poster exists but is empty\n" if (-e $self->path_to('poster') && -z $self->path_to('poster')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $self->path_to("poster") and -z $self->path_to("poster")
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")
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
-e $self->path_to("tracks") and -z $self->path_to("tracks")
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")
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | die "metadata file does not exist\n" unless (-e $self->path_to('metadata')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "metadata file is empty\n" if (-z $self->path_to('metadata')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 0 | chomp $line; | |||||||||||||||||||||||||||
| 56 | 0 | my ($k, $v) = ($line =~ /^(\w+)\s*:\s*(.*?)$/); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | next unless $k; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($k eq $key) { return $v } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 8 | my $dir = $self->directory; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 8 | ▶ | if ($item eq 'video') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||