blib/lib/AudioFile/Info/MP3/Tag.pm

filter: Statementstmt 89.1% 41 / 46 Branchbran 50.0% 10 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 76.2% 61 / 80 CC 12 SCAR 21.3
CC
12
Cov
75%
AUTOLOAD
14.3
DESTROY
3.7
BEGIN
1.0
CRAP 8.4
« lib/AudioFile/Info/Build.pm ↑ Summary
1 =head1 NAME
2  
3 AudioFile::Info::MP3::Tag - Perl extension to get info from MP3 files.
4  
5 =head1 DESCRIPTION
6  
7 This is a plugin for AudioFile::Info which uses MP3::Tag to get or set
8 data about MP3 files.
9  
10 See L<AudioFile::Info> for more details.
11  
12 =cut
13  
14 package AudioFile::Info::MP3::Tag;
15  
16 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use MP3::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 our $VERSION = '1.6.4';
24  
25 3 my %data = (artist => ['artist', 'TPE1'],
26 title => ['song', 'TIT2'],
27 album => ['album', 'TALB'],
28 track => ['track', 'TRCK'],
29 year => ['year', 'TYER'],
30 genre => ['genre', 'TCON']);
31  
32 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
33 3 my $class = shift;
34 3 my $file = shift;
35 3 my $obj = MP3::Tag->new($file);
36 3 $obj->get_tags;
37  
38 3 bless { obj => $obj }, $class;
39 }
40  
41 3 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=13.1
42 3 ▶ my $file = $_[0]->{obj}{ID3v2}{mp3} || $_[0]->{obj}{ID3v2}{mp3};
Condition33%1/3
$_[0]{'obj'}{'ID3v2'}{'mp3'} || $_[0]{'obj'}{'ID3v2'}{'mp3'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$_[0]{'obj'}{'ID3v2'}{'mp3'} || $_[0]{'obj'}{'ID3v2'}{'mp3'}
$_[0]{'obj'}{'ID3v2'}{'mp3'} $_[0]{'obj'}{'ID3v2'}{'mp3'}
Truth table33%1/3
A || B
A= $_[0]{'obj'}{'ID3v2'}{'mp3'}B= $_[0]{'obj'}{'ID3v2'}{'mp3'}
ABresult
1X1
011
000
43  
44 3 ▶ $file->close if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 3 0 3
45 }
46  
47 24 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=10 SCAR=26.6
48 24 our $AUTOLOAD;
49  
50 24 my ($sub) = $AUTOLOAD =~ /::(\w+)$/;
51  
52 24 ▶ die "Invalid attribute $sub" unless exists $data{$sub};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data{$sub} 0 24 24
53  
54 24 ▶ if ($_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]) 6 18 24
55 6 ▶ $_[0]->{obj}->new_tag('ID3v1') unless $_[0]->{obj}{ID3v1};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"obj"}{"ID3v1"} 0 6 6
56 6 ▶ $_[0]->{obj}->new_tag('ID3v2') unless $_[0]->{obj}{ID3v2};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"obj"}{"ID3v2"} 0 6 6
57 6 ▶ if (my $frame = $_[0]->{obj}{ID3v1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frame = $_[0]{"obj"}{"ID3v1"}) 6 0 6
58 6 my $tag = $data{$sub}[0];
59 6 $frame->$tag($_[1]);
60 6 $frame->write_tag;
61 }
62 6 ▶ if (my $frame = $_[0]->{obj}{ID3v2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frame = $_[0]{"obj"}{"ID3v2"}) 6 0 6
63 6 my $tag = $data{$sub}[1];
64 6 ▶ if (exists $frame->get_frame_ids->{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $frame->get_frame_ids->{$tag}) { } 6 0 6
65 6 $frame->change_frame($tag, $_[1]);
66 } else {
67 0 $frame->add_frame($tag, $_[1]);
68 }
69 6 $frame->write_tag;
70 }
71 }
72  
73 24 ▶ if ($_[0]->{obj}{ID3v2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"obj"}{"ID3v2"}) 24 0 24
74 24 return ($_[0]->{obj}{ID3v2}->get_frame($data{$sub}[1]))[0];
75 }
76 0 ▶ if ($_[0]->{obj}{ID3v1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"obj"}{"ID3v1"}) 0 0 0
77 0 my $tag = $data{$sub}[0];
78 0 return $_[0]->{obj}{ID3v1}->$tag;
79 }
80 0 return;
81 }
82  
83  
84 3 1;
85 __END__
« lib/AudioFile/Info/Build.pm ↑ Summary