blib/lib/Audio/Digest/MP3.pm

filter: Statementstmt 81.0% 64 / 79 Branchbran 40.0% 8 / 20 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.2% 16 / 19 Podpod 75.0% 9 / 12 totaltotal 72.0% 98 / 136 CC 13 SCAR 19.1
CC
13
Cov
71%
digest_frames
30.0
format_time
4.1
scan
4.0
CRAP 6.8
↑ Summary
1 package Audio::Digest::MP3;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 our $VERSION = 0.10;
10 1 our @EXPORT_OK = qw(format_time digest_frames);
11 1 our @ISA = 'Exporter';
12  
13 1 ▶use MPEG::Audio::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶sub scan {
Subroutine scan: called CC=4 SCAR=13.9
Pod documented
18 1 my $class = shift;
19 1 my $file = shift;
20 1 ▶ my $ctx = Digest->new(shift || 'MD5');
Condition50%1/2
shift() || 'MD5'
l!l
10
MC/DC0%0/1
shift() || 'MD5'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
21 1 ▶ open my($fh), "<", $file or croak "Can't open file \"$file\": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak(qq[Can't open file "$file": $!]) 1 0 1
22 1 binmode $fh;
23 1 my $frames = 0;
24 1 my $seconds = 0;
25 1 my $bytes = 0;
26 1 my %histogram;
27 1 ▶ while(my $frame = MPEG::Audio::Frame->read($fh)){
Branch: 1 branch
BranchTrueFalseTotal
if (my $frame = "MPEG::Audio::Frame"->read($fh)) 160 1 161
28 160 $ctx->add($frame->asbin);
29 160 $frames++;
30 160 $seconds += $frame->seconds;
31 160 $bytes += length $frame->asbin;
32 160 $histogram{$frame->bitrate}++;
33 }
34 1 return bless [ $ctx->hexdigest, $seconds, $frames, $bytes, \%histogram ], $class;
35 }
36  
37 1 ▶use overload '""' => \&digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶sub digest { shift->[0] };
Subroutine digest: called CC=1 SCAR=0.0
Pod documented
39 2 ▶sub seconds { shift->[1] };
Subroutine seconds: called CC=1 SCAR=0.0
Pod documented
40 0 ▶sub frames { shift->[2] };
Subroutine frames: not called CC=1 SCAR=6.9
Pod documented
41 1 ▶sub bytes { shift->[3] };
Subroutine bytes: called CC=1 SCAR=0.0
Pod documented
42 2 ▶sub histogram { shift->[4] };
Subroutine histogram: called CC=1 SCAR=0.0
Pod undocumented
43 1 ▶sub cbr { 1 == keys %{&histogram} }
Subroutine cbr: called CC=1 SCAR=0.0
Pod documented
44 0 ▶sub vbr { 1 < keys %{&histogram} }
Subroutine vbr: not called CC=1 SCAR=6.9
Pod documented
45  
46 1 ▶sub bitrate {
Subroutine bitrate: called CC=3 SCAR=12.3
Pod documented
47 1 my $self = shift;
48 1 ▶ my $seconds = $self->seconds or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $seconds = $self->seconds or return undef 1 0 1
49 1 ▶ if($self->cbr) { return +(keys %{$self->histogram})[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cbr) 1 0 1
50 0 (my $bitrate = sprintf "%.1f", ($self->bytes/$seconds)*8/1000) =~ s/\.0//;
51 0 return $bitrate;
52 }
53  
54 1 ▶sub playing_time {
Subroutine playing_time: called CC=1 SCAR=0.0
Pod documented
55 1 my $seconds = (shift)->seconds;
56 1 return format_time($seconds, @_);
57 }
58  
59 1 ▶sub format_time {
Subroutine format_time: called CC=4 SCAR=14.1
Pod undocumented
60 1 my $seconds = shift;
61 1 my $digits = shift;
62 1 local *_ = \$seconds;
63 1 ▶ if(defined $digits) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $digits) 1 0 1
64 1 my $abbrev = $digits =~ s/^-//;
65 1 $_ = sprintf "%.$digits\Ef", $_;
66 1 ▶ s/\.?0+$// if $abbrev;
Branch: 1 branch
BranchTrueFalseTotal
if $abbrev 0 1 1
67 }
68 s<^(\d+)>{
69 1 ▶ $1 < 3600 ?
Branch: 1 branch
BranchTrueFalseTotal
$1 < 3600 ? : 1 0 1
70 sprintf "%d:%02d", $1 / 60, $1 % 60
71 : sprintf "%d:%02d:%02d", $1 / 3600, int($1 / 60) % 60, $1 % 60
72 1 }e;
73 1 return $_;
74 }
75  
76 0 ▶sub digest_frames {
Subroutine digest_frames: not called CC=5 SCAR=34.0
Pod undocumented
77 0 my $file = shift;
78 0 ▶ my $ctx = Digest->new(shift || 'MD5');
Condition0%0/2
shift() || 'MD5'
l!l
00
MC/DC0%0/1
shift() || 'MD5'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
79 0 ▶ open my($fh), "<", $file or croak "Can't open file \"$file\": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak(qq[Can't open file "$file": $!]) 0 0 0
80 0 binmode $fh;
81 0 my @digest;
82 0 ▶ while(my $frame = MPEG::Audio::Frame->read($fh)){
Branch: 1 branch
BranchTrueFalseTotal
if (my $frame = "MPEG::Audio::Frame"->read($fh)) 0 0 0
83 0 $ctx->reset;
84 0 $ctx->add($frame->asbin);
85 0 push @digest, $ctx->hexdigest;
86 }
87 0 ▶ return wantarray ? @digest : \@digest;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
88 }
89  
90 1 1;
91  
92 __END__
↑ Summary