File Coverage

blib/lib/Filename/Type/Image.pm
Criterion Covered Total %
statement 11 13 84.6
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 16 21 76.1


line stmt bran cond sub pod time code
1             package Filename::Type::Image;
2              
3 1     1   398522 use 5.010001;
  1         3  
4 1     1   4 use strict;
  1         2  
  1         23  
5 1     1   3 use warnings;
  1         1  
  1         101  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-12-21'; # DATE
9             our $DIST = 'Filename-Type-Image'; # DIST
10             our $VERSION = '0.006'; # VERSION
11              
12 1     1   5 use Exporter qw(import);
  1         2  
  1         191  
13             our @EXPORT_OK = qw(check_image_filename);
14              
15             our $STR_RE = "djvu|jpeg|jpg2|svgz|tiff|wbmp|webp|art|bmp|cdr|cdt|cpt|cr2|crw|djv|erf|gif|ico|ief|jng|jp2|jpe|jpf|jpg|jpm|jpx|nef|orf|pat|pbm|pcx|pgm|png|pnm|ppm|psd|ras|rgb|svg|tif|xbm|xcf|xpm|xwd"; # STR_RE
16              
17             our $RE = qr(\.(?:$STR_RE)\z)i;
18              
19             our %SPEC;
20              
21             $SPEC{check_image_filename} = {
22             v => 1.1,
23             summary => 'Check whether filename indicates being an image',
24             description => <<'MARKDOWN',
25              
26              
27             MARKDOWN
28             args => {
29             filename => {
30             schema => 'filename*',
31             req => 1,
32             pos => 0,
33             },
34             # XXX recurse?
35             #ci => {
36             # summary => 'Whether to match case-insensitively',
37             # schema => 'bool',
38             # default => 1,
39             #},
40             },
41             result_naked => 1,
42             result => {
43             schema => ['any*', of=>['bool*', 'hash*']],
44             description => <<'MARKDOWN',
45              
46             Return false if no archive suffixes detected. Otherwise return a hash of
47             information.
48              
49             MARKDOWN
50             },
51             examples => [
52             {
53             args => {filename => 'foo.txt'},
54             naked_result => 0,
55             },
56             {
57             args => {filename => 'foo.mp4'},
58             naked_result => 0,
59             },
60             {
61             args => {filename => 'foo.jpg'},
62             naked_result => {},
63             },
64             {
65             args => {filename => 'foo.PNG'},
66             naked_result => {},
67             },
68             ],
69             };
70             sub check_image_filename {
71 0     0 1   my %args = @_;
72              
73 0 0         $args{filename} =~ $RE ? {} : 0;
74             }
75              
76             1;
77             # ABSTRACT: Check whether filename indicates being an image
78              
79             __END__