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   806696 use strict;
  15         141  
  15         830  
4              
5             our $VERSION = '1.00';
6              
7             require XSLoader;
8             XSLoader::load('Audio::Scan', $VERSION);
9              
10 15     15   108 use constant FILTER_INFO_ONLY => 1;
  15         39  
  15         1311  
11 15     15   86 use constant FILTER_TAGS_ONLY => 2;
  15         48  
  15         11672  
12              
13             sub scan_info {
14 17     17 1 36606 my ( $class, $path, $opts ) = @_;
15              
16 17   50     80 $opts ||= {};
17 17         28 $opts->{filter} = FILTER_INFO_ONLY;
18              
19 17         34 $class->scan( $path, $opts );
20             }
21              
22             sub scan_tags {
23 15     15 1 31227 my ( $class, $path, $opts ) = @_;
24              
25 15   50     67 $opts ||= {};
26 15         36 $opts->{filter} = FILTER_TAGS_ONLY;
27              
28 15         30 $class->scan( $path, $opts );
29             }
30              
31             sub scan {
32 185     185 1 379822 my ( $class, $path, $opts ) = @_;
33              
34 185         293 my ($filter, $md5_size, $md5_offset);
35              
36 185 50       6386 open my $fh, '<', $path or do {
37 0         0 warn "Could not open $path for reading: $!\n";
38 0         0 return;
39             };
40              
41 185         571 binmode $fh;
42              
43 185         1332 my ($suffix) = $path =~ /\.(\w+)$/;
44              
45 185 50       434 return if !$suffix;
46              
47 185 100       340 if ( defined $opts ) {
48 44 50       115 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     133 $filter = $opts->{filter} || FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
55 44         71 $md5_size = $opts->{md5_size};
56 44         61 $md5_offset = $opts->{md5_offset};
57             }
58             }
59              
60 185 100       293 if ( !defined $filter ) {
61 141         223 $filter = FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
62             }
63              
64 185   100     36865 my $ret = $class->_scan( $suffix, $fh, $path, $filter, $md5_size || 0, $md5_offset || 0 );
      100        
65              
66 185         2234 close $fh;
67              
68 185         1031 return $ret;
69             }
70              
71             sub scan_fh {
72 3     3 1 4678 my ( $class, $suffix, $fh, $opts ) = @_;
73              
74 3         7 my ($filter, $md5_size, $md5_offset);
75              
76 3         9 binmode $fh;
77              
78 3 50       11 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       11 if ( !defined $filter ) {
92 3         6 $filter = FILTER_INFO_ONLY | FILTER_TAGS_ONLY;
93             }
94              
95 3   50     323 return $class->_scan( $suffix, $fh, '(filehandle)', $filter, $md5_size || 0, $md5_offset || 0 );
      50        
96             }
97              
98             sub find_frame {
99 17     17 1 10029 my ( $class, $path, $offset ) = @_;
100              
101 17 50       558 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         61 binmode $fh;
107              
108 17         114 my ($suffix) = $path =~ /\.(\w+)$/;
109              
110 17 50       44 return -1 if !$suffix;
111              
112 17         4299 my $ret = $class->_find_frame( $suffix, $fh, $path, $offset );
113              
114 17         200 close $fh;
115              
116 17         106 return $ret;
117             }
118              
119             sub find_frame_fh {
120 6     6 1 2774 my ( $class, $suffix, $fh, $offset ) = @_;
121              
122 6         15 binmode $fh;
123              
124 6         1084 return $class->_find_frame( $suffix, $fh, '(filehandle)', $offset );
125             }
126              
127             sub find_frame_return_info {
128 3     3 1 2088 my ( $class, $path, $offset ) = @_;
129              
130 3 50       106 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         10 binmode $fh;
136              
137 3         19 my ($suffix) = $path =~ /\.(\w+)$/;
138              
139 3 50       7 return if !$suffix;
140              
141 3         2791 my $ret = $class->_find_frame_return_info( $suffix, $fh, $path, $offset );
142              
143 3         27 close $fh;
144              
145 3         16 return $ret;
146             }
147              
148             sub find_frame_fh_return_info {
149 1     1 1 449 my ( $class, $suffix, $fh, $offset ) = @_;
150              
151 1         2 binmode $fh;
152              
153 1         169 return $class->_find_frame_return_info( $suffix, $fh, '(filehandle)', $offset );
154             }
155              
156             1;
157             __END__