line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Audio::Metadata::Flac::Block::Comments; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Audio::Metadata::Flac::Block::Comments::VERSION = '0.16'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
2
|
|
|
2
|
|
2494
|
$Audio::Metadata::Flac::Block::Comments::VERSION = '0.15'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
17
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
68
|
|
10
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use Any::Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
extends 'Audio::Metadata::Flac::Block'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has vendor => ( isa => 'Str', is => 'rw', ); |
18
|
|
|
|
|
|
|
has comments => ( isa => 'HashRef', is => 'rw', default => sub { {} }, ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub type_code { |
25
|
|
|
|
|
|
|
## Overriden. |
26
|
|
|
|
|
|
|
|
27
|
32
|
|
|
32
|
0
|
108
|
4; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub BUILDARGS { |
32
|
|
|
|
|
|
|
## Parses the block, setting properties. |
33
|
12
|
|
|
12
|
1
|
196
|
my $self = shift; |
34
|
12
|
|
|
|
|
31
|
my ($init_content) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Note that comments are in Vorbis format which uses little-endian byte order |
37
|
|
|
|
|
|
|
# as opposed to FLAC's big-endian. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Parse vendor string. |
40
|
12
|
|
|
|
|
56
|
my $vendor_str_size = unpack('V', $init_content); |
41
|
12
|
|
|
|
|
35
|
my $offset = 4 + $vendor_str_size; |
42
|
12
|
|
|
|
|
67
|
my %result = ( |
43
|
|
|
|
|
|
|
_init_content => $init_content, |
44
|
|
|
|
|
|
|
vendor => substr($init_content, 4, $vendor_str_size), |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Parse comment count. |
48
|
12
|
|
|
|
|
107
|
my $comment_count = unpack('V', substr($init_content, $offset)); |
49
|
12
|
|
|
|
|
29
|
$offset += 4; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Parse comments. |
52
|
12
|
|
|
|
|
38
|
for (1 .. $comment_count) { |
53
|
37
|
|
|
|
|
182
|
my $comment_size = unpack('V', substr($init_content, $offset)); |
54
|
37
|
|
|
|
|
49
|
$offset += 4; |
55
|
37
|
|
|
|
|
331
|
my ($key, $value) = split /=/, substr($init_content, $offset, $comment_size); |
56
|
37
|
|
|
|
|
119
|
$result{comments}{$key} = $value; |
57
|
37
|
|
|
|
|
82
|
$offset += $comment_size; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
12
|
|
|
|
|
279
|
return \%result; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_var { |
65
|
|
|
|
|
|
|
## Returns value for the given var. |
66
|
9
|
|
|
9
|
0
|
16
|
my $self = shift; |
67
|
9
|
|
|
|
|
14
|
my ($var) = @_; |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
56
|
return $self->comments->{$var}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub set_var { |
74
|
|
|
|
|
|
|
## Sets var to given value. 'undef' deletes the var. |
75
|
24
|
|
|
24
|
0
|
42
|
my $self = shift; |
76
|
24
|
|
|
|
|
90
|
my ($var, $value) = @_; |
77
|
|
|
|
|
|
|
|
78
|
24
|
50
|
|
|
|
59
|
if (defined $value) { |
79
|
24
|
|
|
|
|
126
|
$self->comments->{$var} = $value; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
0
|
delete $self->comments->{$var}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub content_as_string { |
88
|
|
|
|
|
|
|
## Overriden. |
89
|
36
|
|
|
36
|
0
|
51
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Pack vendor string. |
92
|
36
|
|
|
|
|
265
|
my $content = pack('V', length($self->vendor)) . $self->vendor; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Add vars. |
95
|
36
|
|
|
|
|
90
|
my $vars = $self->comments; |
96
|
36
|
|
|
|
|
272
|
$content .= pack('V', scalar keys %$vars); |
97
|
36
|
|
|
|
|
144
|
while (my ($var, $value) = each %$vars) { |
98
|
130
|
|
|
|
|
341
|
my $var_str = $var . '=' . $value; |
99
|
130
|
|
|
|
|
970
|
$content .= pack('V', length($var_str)) . $var_str; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
36
|
|
|
|
|
270
|
return $content; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub as_string { |
107
|
|
|
|
|
|
|
## Overriden. |
108
|
8
|
|
|
8
|
0
|
15
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
8
|
|
|
|
|
30
|
return $self->_get_header . $self->content_as_string; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
2
|
|
2774
|
no Any::Moose; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
12
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |