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.
71 lines
1.1 KiB
71 lines
1.1 KiB
package Text::Playlist; |
|
|
|
use strict; |
|
use warnings; |
|
|
|
our $VERSION = 0.1; |
|
|
|
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") } |
|
|
|
sub load { |
|
my ($self, $file) = @_; |
|
|
|
open(my $FH, "<", $file) or return $!; |
|
local $/ = undef; |
|
my $content = <$FH>; |
|
close($FH); |
|
|
|
return $self->parse($content); |
|
} |
|
|
|
sub save { |
|
my ($self, $file) = @_; |
|
|
|
open(my $FH, ">", $file) or die $!; |
|
print $FH $self->dump(); |
|
close($FH); |
|
|
|
return 1; |
|
} |
|
|
|
1; |
|
|
|
=pod |
|
|
|
=head1 NAME |
|
|
|
Text::Playlist -- base class for working with various playlist formats |
|
|
|
=head1 Methods |
|
|
|
=head2 C<items> |
|
|
|
my @items = $pls->items; # array |
|
my $items = $pls->items; # arrayref |
|
|
|
Returns array of playlist items. |
|
|
|
=head2 C<load> |
|
|
|
$pls->load('playlist.pls'); |
|
|
|
Simple helper for loading playlist from file. See also C<parse>. |
|
|
|
=head2 C<save> |
|
|
|
$pls->save('playlist.pls'); |
|
|
|
Simple helper for saving playlist to file. See also C<dump>. |
|
|
|
=head1 AUTHORS |
|
|
|
Alex 'AdUser' Z <ad_user@runbox.com> |
|
|
|
=cut
|
|
|