| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::BibTeX; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.18'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
239667
|
use namespace::clean; |
|
|
1
|
|
|
|
|
16733
|
|
|
|
1
|
|
|
|
|
8
|
|
|
6
|
1
|
|
|
1
|
|
643
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
166136
|
|
|
|
1
|
|
|
|
|
9
|
|
|
7
|
1
|
|
|
1
|
|
866
|
use BibTeX::Parser; |
|
|
1
|
|
|
|
|
11293
|
|
|
|
1
|
|
|
|
|
32
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _contributor_name { |
|
13
|
6
|
|
|
6
|
|
12
|
my ($self, $c) = @_; |
|
14
|
6
|
|
|
|
|
15
|
my $name = $c->to_string; |
|
15
|
6
|
|
|
|
|
216
|
$name =~ tr/\{\}//d; |
|
16
|
6
|
|
|
|
|
20
|
$name; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub generator { |
|
20
|
|
|
|
|
|
|
my ($self) = @_; |
|
21
|
|
|
|
|
|
|
my $fh = $self->fh; |
|
22
|
|
|
|
|
|
|
sub { |
|
23
|
|
|
|
|
|
|
my $parser = BibTeX::Parser->new($fh); |
|
24
|
|
|
|
|
|
|
while (my $entry = $parser->next) { |
|
25
|
|
|
|
|
|
|
my $bib = {}; |
|
26
|
|
|
|
|
|
|
if ($entry->parse_ok) { |
|
27
|
|
|
|
|
|
|
$bib->{type} = lc $entry->type; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$bib->{_citekey} = $entry->key; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if (my @authors = $entry->cleaned_author) { |
|
32
|
|
|
|
|
|
|
$bib->{author} |
|
33
|
|
|
|
|
|
|
= [map {$self->_contributor_name($_)} @authors]; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
if (my @editors = $entry->cleaned_editor) { |
|
36
|
|
|
|
|
|
|
$bib->{editor} |
|
37
|
|
|
|
|
|
|
= [map {$self->_contributor_name($_)} @editors]; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
for my $field ($entry->fieldlist) { |
|
41
|
|
|
|
|
|
|
next if $field =~ /^type|author|editor$/; |
|
42
|
|
|
|
|
|
|
$bib->{$field} = $entry->cleaned_field($field); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return $bib; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
else { |
|
48
|
|
|
|
|
|
|
Catmandu::Error->throw($entry->error); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
return; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Catmandu::Importer::BibTeX - a BibTeX importer |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Catmandu::Importer::BibTeX; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::BibTeX->new(file => "/foo/bar.bib"); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
|
66
|
|
|
|
|
|
|
my $hashref = $_[0]; |
|
67
|
|
|
|
|
|
|
# ... |
|
68
|
|
|
|
|
|
|
}); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Citekey and reference type are imported as field C<_citekey> and C<_type>, |
|
73
|
|
|
|
|
|
|
respectively. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
All methods of L<Catmandu::Importer> and by this L<Catmandu::Iterable> are |
|
78
|
|
|
|
|
|
|
inherited. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L<Catmandu::Exporter::BibTeX>, |
|
83
|
|
|
|
|
|
|
L<BibTeX::Parser> |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |