| 1 | package Catmandu::Exporter::BibTeX; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.21'; | |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 1 | with 'Catmandu::Exporter'; | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | my $TAGS = [ | |||||||||||||||||||||||||||||||||
| 13 | qw( | ||||||||||||||||||||||||||||||||||
| 14 | abstract | ||||||||||||||||||||||||||||||||||
| 15 | address | ||||||||||||||||||||||||||||||||||
| 16 | articleno | ||||||||||||||||||||||||||||||||||
| 17 | author | ||||||||||||||||||||||||||||||||||
| 18 | booktitle | ||||||||||||||||||||||||||||||||||
| 19 | chapter | ||||||||||||||||||||||||||||||||||
| 20 | day | ||||||||||||||||||||||||||||||||||
| 21 | edition | ||||||||||||||||||||||||||||||||||
| 22 | editor | ||||||||||||||||||||||||||||||||||
| 23 | eprint | ||||||||||||||||||||||||||||||||||
| 24 | howpublished | ||||||||||||||||||||||||||||||||||
| 25 | institution | ||||||||||||||||||||||||||||||||||
| 26 | isbn | ||||||||||||||||||||||||||||||||||
| 27 | issn | ||||||||||||||||||||||||||||||||||
| 28 | journal | ||||||||||||||||||||||||||||||||||
| 29 | keywords | ||||||||||||||||||||||||||||||||||
| 30 | language | ||||||||||||||||||||||||||||||||||
| 31 | location | ||||||||||||||||||||||||||||||||||
| 32 | month | ||||||||||||||||||||||||||||||||||
| 33 | note | ||||||||||||||||||||||||||||||||||
| 34 | number | ||||||||||||||||||||||||||||||||||
| 35 | organization | ||||||||||||||||||||||||||||||||||
| 36 | pages | ||||||||||||||||||||||||||||||||||
| 37 | publisher | ||||||||||||||||||||||||||||||||||
| 38 | school | ||||||||||||||||||||||||||||||||||
| 39 | series | ||||||||||||||||||||||||||||||||||
| 40 | title | ||||||||||||||||||||||||||||||||||
| 41 | type | ||||||||||||||||||||||||||||||||||
| 42 | url | ||||||||||||||||||||||||||||||||||
| 43 | doi | ||||||||||||||||||||||||||||||||||
| 44 | volume | ||||||||||||||||||||||||||||||||||
| 45 | year | ||||||||||||||||||||||||||||||||||
| 46 | ) | ||||||||||||||||||||||||||||||||||
| 47 | ]; | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 1 | my $JOIN = {author => ' and ', editor => ' and ', language => ',', | |||||||||||||||||||||||||||||||||
| 50 | keywords => ',',}; | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | sub add { | ||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=10 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 53 | 1 | my ($self, $orig_data) = @_; | |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 1 | my $data = clone($orig_data); | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 1 | my $fh = $self->fh; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | my $type = $data->{type} || $data->{_type} || 'misc'; | ||||||||||||||||||||||||||||||||
|
Condition40%2/5
$data->{'type'} || $data->{'_type'} || 'misc'
$data->{"type"} or $data->{"_type"}
MC/DC0%0/2
$data->{'type'} || $data->{'_type'} || 'misc'
$data->{"type"}
$data->{"_type"}
Truth table33%1/3
A or B
A= $data->{"type"}B= $data->{"_type"}
| |||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | my $citekey = $data->{_citekey} || $data->{_id} || $self->count + 1; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$data->{'_citekey'} || $data->{'_id'} || $self->count + 1
$data->{"_citekey"} or $data->{"_id"}
MC/DC0%0/3
$data->{'_citekey'} || $data->{'_id'} || $self->count + 1
$data->{"_citekey"}
$data->{"_id"}
$self->count + 1
Truth table25%1/4
A or B || C
A= $data->{"_citekey"}B= $data->{"_id"}C= $self->count + 1
| |||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 1 | for my $tag (keys %$JOIN) { | |||||||||||||||||||||||||||||||||
| 63 | 4 | my $val = $data->{$tag}; | |||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | if ($val && ref($val) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val and ref $val eq "ARRAY"
MC/DC100%2/2
$val and ref $val eq "ARRAY"
$val
ref $val eq "ARRAY"
Truth table100%3/3
A and B
A= $valB= ref $val eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 65 | 1 | $data->{$tag} = join $JOIN->{$tag}, @$val; | |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 1 | print $fh "\@$type\{$citekey,\n"; | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 1 | for my $tag (@$TAGS) { | |||||||||||||||||||||||||||||||||
| 72 | 32 | ▶ | if (my $val = $data->{$tag}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | 6 | printf $fh " %-12s = {{%s}},\n", $tag, $val; | |||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 1 | print $fh "}\n\n"; | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | Catmandu::Exporter::BibTeX - a BibTeX exporter | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | use Catmandu::Exporter::BibTeX; | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | my $exporter = Catmandu::Exporter::BibTeX->new(fix => 'myfix.txt'); | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | $exporter->add_many($arrayref); | ||||||||||||||||||||||||||||||||||
| 91 | $exporter->add_many($iterator); | ||||||||||||||||||||||||||||||||||
| 92 | $exporter->add_many(sub { }); | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | $exporter->add($hashref); | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | $exporter->add({ | ||||||||||||||||||||||||||||||||||
| 97 | type => 'book', | ||||||||||||||||||||||||||||||||||
| 98 | _citekey => '389-ajk0-1', | ||||||||||||||||||||||||||||||||||
| 99 | title => 'the Zen of {CSS} design', | ||||||||||||||||||||||||||||||||||
| 100 | author => ['Dave Shea','Molley E. Holzschlag'], | ||||||||||||||||||||||||||||||||||
| 101 | isbn => '0-321-30347-4' | ||||||||||||||||||||||||||||||||||
| 102 | }); | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | printf "exported %d objects\n" , $exporter->count; | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | The BibTeX L<Catmandu::Exporter> requires as input a Perl hash (or a fix) | ||||||||||||||||||||||||||||||||||
| 109 | containing BibTeX fields and values as a string or array reference. | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | =head1 SUPPORTED FIELDS | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | Two special fields can be set in the Perl hash: | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | =over | ||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | =item C<type> or C<_type> | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | to describe the document type (article, book, ...). Set to 'misc' by default. | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | =item C<_citekey> or C<_id> | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | to describt the citation key. The next counter value (starting from 1) is used | ||||||||||||||||||||||||||||||||||
| 124 | by default. | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | =back | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | The following BibTeX fields are supported. All other fields are ignored. | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | abstract | ||||||||||||||||||||||||||||||||||
| 131 | address | ||||||||||||||||||||||||||||||||||
| 132 | author | ||||||||||||||||||||||||||||||||||
| 133 | booktitle | ||||||||||||||||||||||||||||||||||
| 134 | chapter | ||||||||||||||||||||||||||||||||||
| 135 | day | ||||||||||||||||||||||||||||||||||
| 136 | edition | ||||||||||||||||||||||||||||||||||
| 137 | editor | ||||||||||||||||||||||||||||||||||
| 138 | eprint | ||||||||||||||||||||||||||||||||||
| 139 | howpublished | ||||||||||||||||||||||||||||||||||
| 140 | institution | ||||||||||||||||||||||||||||||||||
| 141 | isbn | ||||||||||||||||||||||||||||||||||
| 142 | issn | ||||||||||||||||||||||||||||||||||
| 143 | journal | ||||||||||||||||||||||||||||||||||
| 144 | keywords | ||||||||||||||||||||||||||||||||||
| 145 | language | ||||||||||||||||||||||||||||||||||
| 146 | location | ||||||||||||||||||||||||||||||||||
| 147 | month | ||||||||||||||||||||||||||||||||||
| 148 | note | ||||||||||||||||||||||||||||||||||
| 149 | number | ||||||||||||||||||||||||||||||||||
| 150 | organization | ||||||||||||||||||||||||||||||||||
| 151 | pages | ||||||||||||||||||||||||||||||||||
| 152 | publisher | ||||||||||||||||||||||||||||||||||
| 153 | school | ||||||||||||||||||||||||||||||||||
| 154 | series | ||||||||||||||||||||||||||||||||||
| 155 | title | ||||||||||||||||||||||||||||||||||
| 156 | type | ||||||||||||||||||||||||||||||||||
| 157 | url | ||||||||||||||||||||||||||||||||||
| 158 | doi | ||||||||||||||||||||||||||||||||||
| 159 | volume | ||||||||||||||||||||||||||||||||||
| 160 | year | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | Use L<Catmandu::Fix::expand_date> to expand a date field with year, month, and day | ||||||||||||||||||||||||||||||||||
| 165 | into the corresponding BibTeX fields. | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 1 | 1; | |||||||||||||||||||||||||||||||||