| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Ogg::Vorbis::Header; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use 5.006; |
|
4
|
|
|
|
|
|
|
use strict; |
|
5
|
|
|
|
|
|
|
use warnings; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Inline C => 'DATA', |
|
10
|
|
|
|
|
|
|
LIBS => '-logg -lvorbis -lvorbisfile', |
|
11
|
|
|
|
|
|
|
INC => '-I/inc', |
|
12
|
|
|
|
|
|
|
AUTO_INCLUDE => '#include "inc/vcedit.h"', |
|
13
|
|
|
|
|
|
|
AUTO_INCLUDE => '#include "inc/vcedit.c"', |
|
14
|
|
|
|
|
|
|
VERSION => '0.05', |
|
15
|
|
|
|
|
|
|
NAME => 'Ogg::Vorbis::Header'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# constructors |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# wrap this so $obj->new will work right |
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
0
|
|
|
0
|
1
|
|
my ($id, $path) = @_; |
|
22
|
0
|
|
0
|
|
|
|
$id = ref($id) || $id; |
|
23
|
0
|
|
|
|
|
|
_new($id, $path); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub load { |
|
27
|
0
|
|
|
0
|
1
|
|
my ($id, $path) = @_; |
|
28
|
0
|
0
|
|
|
|
|
unless (ref($id)) { |
|
29
|
0
|
|
|
|
|
|
$id = _new($id, $path); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
0
|
|
|
|
|
return $id unless $id; |
|
32
|
0
|
|
|
|
|
|
$id->_load_info; |
|
33
|
0
|
|
|
|
|
|
$id->_load_comments; |
|
34
|
0
|
|
|
|
|
|
return $id; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# A number of the instance methods may be handled with perl code. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub info { |
|
40
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
|
41
|
0
|
0
|
|
|
|
|
$self->_load_info unless $self->{INFO}; |
|
42
|
0
|
0
|
|
|
|
|
if ($key) { |
|
43
|
0
|
|
|
|
|
|
return $self->{INFO}->{$key} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
0
|
|
|
|
|
|
return $self->{INFO}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub comment_tags { |
|
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
50
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
51
|
0
|
|
|
|
|
|
return keys %{$self->{COMMENTS}}; |
|
|
0
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub comment { |
|
55
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
|
56
|
0
|
|
|
|
|
|
my $result; |
|
57
|
0
|
0
|
|
|
|
|
return undef unless $key; |
|
58
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
59
|
0
|
0
|
|
|
|
|
if (! defined ($result = $self->{COMMENTS}->{$key})) { |
|
60
|
0
|
|
|
|
|
|
return undef; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
return @{$result}; |
|
|
0
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub add_comments { |
|
66
|
0
|
|
|
0
|
1
|
|
my ($self, @comments) = @_; |
|
67
|
|
|
|
|
|
|
# For now play it safe limit both tag and field to minimal ascii |
|
68
|
|
|
|
|
|
|
# will work on utf8 in field later |
|
69
|
0
|
0
|
0
|
|
|
|
return undef if @comments < 2 or @comments % 2 != 0; |
|
70
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
71
|
0
|
|
|
|
|
|
while ($#comments >= 0) { |
|
72
|
0
|
|
|
|
|
|
my $key = shift @comments; |
|
73
|
0
|
|
|
|
|
|
$key =~ s/[^\x20-\x3C\x3E-\x7D]//g; |
|
74
|
0
|
|
|
|
|
|
$key = lc($key); |
|
75
|
0
|
|
|
|
|
|
my $val = shift @comments; |
|
76
|
0
|
|
|
|
|
|
$val =~ s/[^\x20-\x7D]//g; |
|
77
|
0
|
|
|
|
|
|
push @{$self->{COMMENTS}->{$key}}, $val; |
|
|
0
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return 1; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub edit_comment { |
|
84
|
0
|
|
|
0
|
1
|
|
my ($self, $key, $value, $num) = @_; |
|
85
|
0
|
|
0
|
|
|
|
$num ||= 0; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
return undef unless $key and $value and $num =~ /^\d*$/; |
|
|
|
|
0
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $comment = $self->{COMMENTS}->{$key}; |
|
91
|
0
|
0
|
|
|
|
|
return undef unless $comment; |
|
92
|
0
|
|
|
|
|
|
$value =~ s/[^\x20-\x7D]//g; |
|
93
|
0
|
0
|
|
|
|
|
return undef unless @$comment > $num; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $result = $comment->[$num]; |
|
96
|
0
|
|
|
|
|
|
$comment->[$num] = $value; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $result; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub delete_comment { |
|
102
|
0
|
|
|
0
|
1
|
|
my ($self, $key, $num) = @_; |
|
103
|
0
|
|
0
|
|
|
|
$num ||= 0; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
0
|
|
|
|
return undef unless $key and $num =~ /^\d*$/; |
|
106
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $comment = $self->{COMMENTS}->{$key}; |
|
109
|
0
|
0
|
|
|
|
|
return undef unless $comment; |
|
110
|
0
|
0
|
|
|
|
|
return undef unless @$comment > $num; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $result = splice @$comment, $num, 1; |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if (@$comment == 0) { |
|
115
|
0
|
|
|
|
|
|
delete($self->{COMMENTS}->{$key}); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return $result; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub clear_comments { |
|
122
|
0
|
|
|
0
|
1
|
|
my ($self, @keys) = @_; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
$self->_load_comments unless $self->{COMMENTS}; |
|
125
|
0
|
0
|
|
|
|
|
if (@keys) { |
|
126
|
0
|
|
|
|
|
|
foreach (@keys) { |
|
127
|
0
|
0
|
|
|
|
|
return undef unless $self->{COMMENTS}->{$_}; |
|
128
|
0
|
|
|
|
|
|
delete($self->{COMMENTS}->{$_}); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} else { |
|
131
|
0
|
|
|
|
|
|
foreach (keys %{$self->{COMMENTS}}) { |
|
|
0
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
delete($self->{COMMENTS}->{$_}); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
0
|
|
|
|
|
|
return 1; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub path { |
|
139
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
140
|
0
|
|
|
|
|
|
return $self->{PATH}; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
|
144
|
|
|
|
|
|
|
__DATA__ |