You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.4 KiB

10 years ago
package Text::Playlist;
use strict;
use warnings;
our $VERSION = '0.02';
10 years ago
sub items {
my ($self) = @_;
return wantarray ? @{$self->{items}} : $self->{items};
}
sub parse { die("must be implemented by subclass\n") }
sub dump { die("must be implemented by subclass\n") }
10 years ago
sub load {
my ($self, $file) = @_;
open(my $FH, "<", $file) or return $!;
local $/ = undef;
my $content = <$FH>;
close($FH);
return $self->parse($content);
}
sub save {
10 years ago
my ($self, $file, @items) = @_;
10 years ago
open(my $FH, ">", $file) or die $!;
10 years ago
print $FH $self->dump(@items);
10 years ago
close($FH);
return 1;
}
1;
=pod
=head1 NAME
Text::Playlist -- base class for work with various playlist formats
10 years ago
=head1 DESCRIPTION
This module acts only as base class for specific parsers.
=head1 Methods
10 years ago
=head2 C<load>
10 years ago
my @items = $pls->load('playlist.pls');
10 years ago
Simple helper for loading playlist from file. See also C<parse>.
10 years ago
=head2 C<parse>
10 years ago
my @items = $pls->parse($text);
10 years ago
Takes playlist text and returns array of hashrefs with playlist items. In scalar content returns arrayref.
=head2 C<save>
10 years ago
$pls->save('playlist.pls', @items);
Simple helper for saving playlist to file. See also C<dump>.
10 years ago
=head2 C<dump>
my $text = $pls->dump(@items);
Takes array of hashrefs with playlist items and returns constructed playlist.
10 years ago
=head1 SEE ALSO
L<Text::Playlist::M3U>, L<Text::Playlist::PLS>, L<Text::Playlist::XSPF>
=head1 AUTHORS
10 years ago
* Alex 'AdUser' Z <aduser@cpan.org>
=cut