line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Audio::Metadata; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Audio::Metadata::VERSION = '0.16'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
3
|
|
|
3
|
|
51279
|
$Audio::Metadata::VERSION = '0.15'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
25
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
97
|
|
10
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
84
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
3063
|
use Path::Class; |
|
3
|
|
|
|
|
200756
|
|
|
3
|
|
|
|
|
227
|
|
13
|
3
|
|
|
3
|
|
1765
|
use Any::Moose; |
|
3
|
|
|
|
|
74810
|
|
|
3
|
|
|
|
|
24
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has path => ( isa => 'Path::Class::File', is => 'ro', ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILDARGS { |
23
|
|
|
|
|
|
|
## Builds object from file name given as string. |
24
|
12
|
|
|
12
|
1
|
171
|
my $self = shift; |
25
|
12
|
|
|
|
|
23
|
my ($file_name) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return { |
28
|
12
|
|
|
|
|
100
|
path => Path::Class::File->new($file_name), |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new_from_path { |
34
|
|
|
|
|
|
|
## Reads file with given name and returns an object representing it. Object is of type specific |
35
|
|
|
|
|
|
|
## to the codec, i.e.: Audio::Tag::PlainText::AudioFile::Flac, Audio::Tag::PlainText::AudioFile::Mp3 |
36
|
12
|
|
|
12
|
1
|
2718
|
my $class = shift; |
37
|
12
|
|
|
|
|
25
|
my ($file_path) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Derive type-specific module name from file extension. |
40
|
12
|
|
|
|
|
93
|
my ($extension) = $file_path =~ /\.([^.]+)$/; |
41
|
12
|
|
|
|
|
60
|
my $file_class_name = __PACKAGE__ . '::' . ucfirst($extension); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Load appropriate module, instantiate file object and return it. |
44
|
12
|
50
|
|
|
|
765
|
eval "require $file_class_name" |
45
|
|
|
|
|
|
|
or die "Could not load plugin for file extension \"$extension\" ($file_path): $@\n"; |
46
|
12
|
|
|
|
|
130
|
return $file_class_name->new($file_path); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub file_path { |
51
|
|
|
|
|
|
|
## Returns absolute path to the file. |
52
|
14
|
|
|
14
|
1
|
28
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
14
|
50
|
|
|
|
130
|
die 'Cannot return path until file is specified' unless $self->path; |
55
|
14
|
|
|
|
|
146
|
return $self->path->absolute . ''; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_var { |
60
|
|
|
|
|
|
|
## Returns value of specified metadata variable. |
61
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
62
|
0
|
|
|
|
|
0
|
my ($var) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
die 'Call to abstract method'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub set_var { |
69
|
|
|
|
|
|
|
## Sets specified metadata variable to given value. Value of 'undef' will prompt |
70
|
|
|
|
|
|
|
## removal of the variable, if underlying format permits. |
71
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
72
|
0
|
|
|
|
|
0
|
my ($var, $value) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
die 'Call to abstract method'; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub vars_as_hash { |
79
|
|
|
|
|
|
|
## Returns metadata as hash reference. |
80
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
die 'Call to abstract method'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub as_text { |
87
|
|
|
|
|
|
|
## Returns complete file information as space-separated key/value |
88
|
|
|
|
|
|
|
## pairs in multi-line string. |
89
|
4
|
|
|
4
|
1
|
735
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
19
|
my $vars = $self->vars_as_hash; |
92
|
4
|
|
|
|
|
24
|
return join("\n", |
93
|
|
|
|
|
|
|
'_FILE_NAME ' . $self->file_path, |
94
|
|
|
|
|
|
|
map $_ . ' ' . $vars->{$_}, sort keys %$vars) . "\n"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub save { |
99
|
|
|
|
|
|
|
## Writes metadata to file. |
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
die 'Call to abstract method'; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub file_to_text { |
107
|
|
|
|
|
|
|
## Class method. Returns text metadata for the specified file. |
108
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
109
|
0
|
|
|
|
|
|
my ($path) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $metadata = $class->new_from_path($path); |
112
|
0
|
|
|
|
|
|
return $metadata->as_text; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
3
|
|
|
3
|
|
3726
|
no Any::Moose; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |