Subject: | Playlist of 0 failure |
Date: | Thu, 29 Aug 2019 02:12:01 -0400 |
To: | bug-Mac-iTunes-Library [...] rt.cpan.org |
From: | Gary Allen Vollink <gary [...] vollink.com> |
I'm parsing my iTunes library, and I ran into an issue with a fairly simple
program...
---------------------------------------------------------
use Mac::iTunes::Library::XML;
my $sfn = '/media/music/iTunes/iTunes Music Library.xml';
my $library = Mac::iTunes::Library::XML->parse($sfn);
my %playlists = $library->playlists();
printf "LISTID: COUNT NAME\n";
foreach my $listid ( keys %playlists ) {
my $list = $playlists{$listid};
my $name = $list->name();
my $count = $list->num();
printf "%6s: % 6d %s\n", $listid, $count, $name;
}
---------------------------------------------------------
This would pop-up at random times.
Can't use an undefined value as an ARRAY reference at
/usr/local/share/perl/5.26.1/Mac/iTunes/Library/Playlist.pm line 272.
Or, the call to $list->num();
I figured out that it was coming from a playlist where all the songs had
been removed. I worked around the issue already by checking for the
existance of items before calling num(), though my original plan was to
call num to find out if I needed to enumerate the list of items.
Suggestion for Playlist.pm: line 268:
sub num {
my $self = shift;
return NaN if ! defined( $self->{'items'} );
return scalar(@{$self->{'items'}});
} #num
Though there may be other places where a similar check would be beneficial
to other users with questionable playlist hygiene.
Thank you,
Gary