line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Playlist::PLS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
450
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base 'Text::Playlist'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
235
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
0
|
295
|
my ($class) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
2
|
return bless({ }, $class); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse { |
17
|
1
|
|
|
1
|
1
|
1
|
my ($self, $text) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
10
|
my @lines = split /\r?\n/, $text; |
20
|
1
|
|
|
|
|
1
|
my @items = (); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# safeguard |
23
|
6
|
|
|
|
|
8
|
return "Not looks like playlist" |
24
|
1
|
50
|
|
|
|
1
|
unless grep { $_ eq "[playlist]" } @lines; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
1
|
my $count = 0; |
27
|
1
|
|
|
|
|
2
|
foreach my $line (@lines) { |
28
|
6
|
100
|
|
|
|
23
|
if ($line =~ m/(File|Title|Length)(\d+)\s*=\s*(.*)/oi) { |
29
|
3
|
|
|
|
|
9
|
my ($key, $num, $value) = (lc($1), $2 - 1, $3); |
30
|
3
|
|
|
|
|
18
|
$value =~ s/(^\s*|\s*$)//og; |
31
|
3
|
|
100
|
|
|
8
|
$items[$num] //= {}; |
32
|
3
|
|
|
|
|
4
|
$items[$num]->{$key} = $value; |
33
|
3
|
|
|
|
|
3
|
next; |
34
|
|
|
|
|
|
|
} |
35
|
3
|
100
|
|
|
|
7
|
if ($line =~ m/numberofentries\s*=\s*(\d+)/oi) { |
36
|
1
|
|
|
|
|
2
|
$count = $1; |
37
|
1
|
|
|
|
|
2
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
4
|
warn "Number of entries not matches parsed items" |
42
|
|
|
|
|
|
|
if ($count != scalar @items); |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
6
|
return wantarray ? @items : [ @items ]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub dump { |
48
|
1
|
|
|
1
|
1
|
591
|
my ($self, @items) = @_; |
49
|
1
|
|
|
|
|
1
|
my $count = 0; |
50
|
1
|
|
|
|
|
1
|
my @lines = ('[playlist]'); |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
2
|
foreach my $item (@items) { |
53
|
1
|
|
|
|
|
1
|
$count += 1; |
54
|
1
|
|
|
|
|
1
|
foreach my $key (qw(file title length)) { |
55
|
3
|
|
|
|
|
10
|
push @lines, sprintf("%s%d=%s", ucfirst($key), $count, $item->{$key}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
splice(@lines, 1, 0, sprintf("numberofentries=%d", $count)); |
60
|
1
|
|
|
|
|
1
|
push @lines, "Version=2", ""; |
61
|
1
|
|
|
|
|
6
|
return join("\n", @lines); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |