File Coverage

blib/lib/Audio/Scan.pm
Criterion Covered Total %
statement 62 76 81.5
branch 13 24 54.1
condition 10 16 62.5
subroutine 11 11 100.0
pod 8 8 100.0
total 104 135 77.0


line stmt bran cond sub pod time code
1             package Audio::Scan;
2              
3 15     15   1070888 use strict;
  15         183  
  15         1088  
4              
5             our $VERSION = '0.99';
6              
7             require XSLoader;
8             XSLoader::load('Audio::Scan', $VERSION);
9              
10 15     15   115 use constant FILTER_INFO_ONLY => 1;
  15         33  
  15         1484  
11 15     15   112 use constant FILTER_TAGS_ONLY => 2;
  15         49  
  15         14273  
12              
13             sub scan_info {
14 17     17 1 47824 my ( $class, $path, $opts ) = @_;
15              
16 17   50     148 $opts ||= {};
17 17         45 $opts->{filter} = FILTER_INFO_ONLY;
18              
19 17         57 $class->scan( $path, $opts );
20             }
21              
22             sub scan_tags {
23 15     15 1 35730 my ( $class, $path, $opts ) = @_;
24              
25 15   50     80 $opts ||= {};
26 15         43 $opts->{filter} = FILTER_TAGS_ONLY;
27              
28 15         38 $class->scan( $path, $opts );
29             }
30              
31             sub scan {
32 184     184 1 458551 my ( $class, $path, $opts ) = @_;
33              
34 184         377 my ($filter, $md5_size, $md5_offset);
35              
36 184 50       5921 open my $fh, '<', $path or do {
37 0         0 warn "Could not open $path for reading: $!\n";
38 0         0 return;
39             };
40              
41 184         636 binmode $fh;
42              
43 184         1531 my ($suffix) = $path =~ /\.(\w+)$/;
44              
45 184 50       585 return if !$suffix;
46              
47 184 100       487 if ( defined $opts ) {
48 44 50       159 if ( !ref $opts ) {
49             # Back-compat to support filter as normal argument
50 0         0 warn "The Audio::Scan::scan() filter passing method is deprecated, please pass a hashref instead.\n";
51 0         0 $filter = $opts;
52             }
53             else {
54 44   100     181 $filter = $opts->{filter} || FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
55 44         90 $md5_size = $opts->{md5_size};
56 44         92 $md5_offset = $opts->{md5_offset};
57             }
58             }
59              
60 184 100       429 if ( !defined $filter ) {
61 140         243 $filter = FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
62             }
63              
64 184   100     34148 my $ret = $class->_scan( $suffix, $fh, $path, $filter, $md5_size || 0, $md5_offset || 0 );
      100        
65              
66 184         1634 close $fh;
67              
68 184         1021 return $ret;
69             }
70              
71             sub scan_fh {
72 3     3 1 5799 my ( $class, $suffix, $fh, $opts ) = @_;
73              
74 3         8 my ($filter, $md5_size, $md5_offset);
75              
76 3         9 binmode $fh;
77              
78 3 50       16 if ( defined $opts ) {
79 0 0       0 if ( !ref $opts ) {
80             # Back-compat to support filter as normal argument
81 0         0 warn "The Audio::Scan::scan_fh() filter passing method is deprecated, please pass a hashref instead.\n";
82 0         0 $filter = $opts;
83             }
84             else {
85 0   0     0 $filter = $opts->{filter} || FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
86 0         0 $md5_size = $opts->{md5_size};
87 0         0 $md5_offset = $opts->{md5_offset};
88             }
89             }
90              
91 3 50       13 if ( !defined $filter ) {
92 3         10 $filter = FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
93             }
94              
95 3   50     355 return $class->_scan( $suffix, $fh, '(filehandle)', $filter, $md5_size || 0, $md5_offset || 0 );
      50        
96             }
97              
98             sub find_frame {
99 17     17 1 16088 my ( $class, $path, $offset ) = @_;
100              
101 17 50       561 open my $fh, '<', $path or do {
102 0         0 warn "Could not open $path for reading: $!\n";
103 0         0 return;
104             };
105              
106 17         68 binmode $fh;
107              
108 17         153 my ($suffix) = $path =~ /\.(\w+)$/;
109              
110 17 50       62 return -1 if !$suffix;
111              
112 17         4033 my $ret = $class->_find_frame( $suffix, $fh, $path, $offset );
113              
114 17         149 close $fh;
115              
116 17         140 return $ret;
117             }
118              
119             sub find_frame_fh {
120 6     6 1 4638 my ( $class, $suffix, $fh, $offset ) = @_;
121              
122 6         22 binmode $fh;
123              
124 6         1076 return $class->_find_frame( $suffix, $fh, '(filehandle)', $offset );
125             }
126              
127             sub find_frame_return_info {
128 3     3 1 2112 my ( $class, $path, $offset ) = @_;
129              
130 3 50       73 open my $fh, '<', $path or do {
131 0         0 warn "Could not open $path for reading: $!\n";
132 0         0 return;
133             };
134              
135 3         8 binmode $fh;
136              
137 3         19 my ($suffix) = $path =~ /\.(\w+)$/;
138              
139 3 50       10 return if !$suffix;
140              
141 3         2553 my $ret = $class->_find_frame_return_info( $suffix, $fh, $path, $offset );
142              
143 3         20 close $fh;
144              
145 3         14 return $ret;
146             }
147              
148             sub find_frame_fh_return_info {
149 1     1 1 478 my ( $class, $suffix, $fh, $offset ) = @_;
150              
151 1         3 binmode $fh;
152              
153 1         162 return $class->_find_frame_return_info( $suffix, $fh, '(filehandle)', $offset );
154             }
155              
156             1;
157             __END__