use
vars
qw /$VERSION
@ISA
/;
$VERSION
=
"0.01"
;
@ISA
=
'MP3::Tag::__hasparent'
;
sub
new_with_parent {
my
(
$class
,
$filename
,
$parent
) =
@_
;
my
$self
=
bless
{
parent
=>
$parent
},
$class
;
$filename
=
$filename
->filename
if
ref
$filename
;
my
$ext_rex
=
$self
->get_config(
'extension'
)->[0];
$filename
=~ s/(
$ext_rex
)|$/.inf/;
return
unless
-f
$filename
;
$self
->{filename} =
$filename
;
$self
;
}
sub
DESTROY {}
sub
return_parsed {
my
(
$self
,
$what
) =
@_
;
if
(
defined
$what
) {
return
$self
->{parsed}{album}
if
$what
=~/^al/i;
return
$self
->{parsed}{artist}
if
$what
=~/^a/i;
return
$self
->{parsed}{track}
if
$what
=~/^
tr
/i;
return
$self
->{parsed}{year}
if
$what
=~/^y/i;
return
$self
->{parsed}{comment}
if
$what
=~/^c/i;
return
$self
->{parsed}{genre}
if
$what
=~/^g/i;
return
$self
->{parsed}{title};
}
return
$self
->{parsed}
unless
wantarray
;
return
map
$self
->{parsed}{
$_
} ,
qw(title artist album year comment track)
;
}
sub
parse {
my
(
$self
,
$what
) =
@_
;
$self
->return_parsed(
$what
)
if
exists
$self
->{parsed};
local
*IN
;
open
IN,
"< $self->{filename}"
or
die
"Error opening `$self->{filename}': $!"
;
my
(
$line
,
%info
);
for
$line
(<IN>) {
$self
->{info}{
ucfirst
lc
$1} = $2
if
$line
=~ /^(\S+)\s*=\s*[
'"]?(.*?)['
"]?\s*$/;
}
close
IN or
die
"Error closing `$self->{filename}': $!"
;
my
%parsed
;
@parsed
{
qw( title artist album year comment track )
} =
@{
$self
->{info} }{
qw( Tracktitle Performer Albumtitle
Year Trackcomment Tracknumber)
};
$parsed
{artist} =
$self
->{info}{Albumperformer}
unless
defined
$parsed
{artist};
$self
->{parsed} = \
%parsed
;
$self
->return_parsed(
$what
);
}
for
my
$elt
(
qw( title track artist album comment year genre )
) {
no
strict
'refs'
;
*$elt
=
sub
(;$) {
my
$self
=
shift
;
$self
->parse(
$elt
,
@_
);
}
}
1;