File Coverage

blib/lib/Filename/Video.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Filename::Video;
2              
3 2     2   440767 use 5.010001;
  2         8  
4 2     2   11 use strict;
  2         11  
  2         66  
5 2     2   16 use warnings;
  2         4  
  2         179  
6              
7 2     2   13 use Exporter qw(import);
  2         5  
  2         800  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2024-01-12'; # DATE
11             our $DIST = 'Filename-Video'; # DIST
12             our $VERSION = '0.006'; # VERSION
13              
14             our @EXPORT_OK = qw(check_video_filename);
15              
16             our $STR_RE = "movie|mpeg|webm|3gp|asf|asx|avi|axv|dif|fli|flv|lsf|lsx|mkv|mng|mov|mp4|mpe|mpg|mpv|mxu|ogv|wmv|wmx|wvx|dl|dv|gl|qt|ts|wm"; # STR_RE
17              
18             our $RE = qr(\A(.+)\.($STR_RE)\z)i;
19              
20             our %SPEC;
21              
22             $SPEC{check_video_filename} = {
23             v => 1.1,
24             summary => 'Check whether filename indicates being a video file',
25             description => <<'_',
26              
27              
28             _
29             args => {
30             filename => {
31             schema => 'filename*',
32             req => 1,
33             pos => 0,
34             },
35             },
36             result_naked => 1,
37             result => {
38             schema => ['any*', of=>['bool*', 'hash*']],
39             description => <<'_',
40              
41             Return false if no archive suffixes detected. Otherwise return a hash of
42             information.
43              
44             _
45             },
46             examples => [
47             {
48             args => {filename => 'foo.txt'},
49             naked_result => 0,
50             },
51             {
52             args => {filename => 'foo.DOC'},
53             naked_result => 0,
54             },
55             {
56             args => {filename => 'foo.webm'},
57             naked_result => {filename=>'foo.webm', filename_without_suffix=>"foo", suffix=>"webm"},
58             },
59             {
60             args => {filename => 'foo.MP4'},
61             naked_result => {filename=>'foo.MP4', filename_without_suffix=>"foo", suffix=>"MP4"},
62             },
63             ],
64             };
65             sub check_video_filename {
66 5     5 1 474370 my %args = @_;
67              
68 5 100       140 $args{filename} =~ $RE ? {filename=>"$1.$2", filename_without_suffix=>$1, suffix=>$2} : 0;
69             }
70              
71             1;
72             # ABSTRACT: Check whether filename indicates being a video file
73              
74             __END__