line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# --*-Perl-*-- |
2
|
|
|
|
|
|
|
# $Id: Biblio.pm 13 2004-11-27 08:58:44Z tandler $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Biblio::Biblio - Interface class for bibliographic databases
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Biblio::Biblio;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $bib = new Biblio::Biblio('file' => 'sample.bib')
|
14
|
|
|
|
|
|
|
or die "Can't open bibliographic database!\n";
|
15
|
|
|
|
|
|
|
my $bib = new Biblio::Biblio(qw(
|
16
|
|
|
|
|
|
|
class Database
|
17
|
|
|
|
|
|
|
dbms mysql
|
18
|
|
|
|
|
|
|
dbhost samplehost
|
19
|
|
|
|
|
|
|
dbname biblio
|
20
|
|
|
|
|
|
|
dbuser biblio
|
21
|
|
|
|
|
|
|
dbpass biblio
|
22
|
|
|
|
|
|
|
shortcuts_table shortcuts
|
23
|
|
|
|
|
|
|
)) or die "Can't open bibliographic database!\n";
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $refs = $bib->queryPapers();
|
26
|
|
|
|
|
|
|
print join(', ', keys(%{$refs})), "\n";
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Class Biblio provides an abstract interface for bibliographic
|
31
|
|
|
|
|
|
|
databases. It also can be used as a factory for a concrete
|
32
|
|
|
|
|
|
|
database implementation.
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Supported database classes are:
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item Biblio::Database
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
All databases that can be accessed through Perl's DBI module.
|
41
|
|
|
|
|
|
|
The mapping of database fields can be configured (arguments
|
42
|
|
|
|
|
|
|
'column-mapping' and 'column-types', see OOo-table.pbib for an
|
43
|
|
|
|
|
|
|
example).
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item Biblio::File
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Several kind of files, such as bibtex, refer, endnote, tib.
|
48
|
|
|
|
|
|
|
This uses the cool bp package, a Perl Bibliography Package by Dana Jacobsen (dana@acm.org).
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item I
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
You can write your own subclass and pass the class name as the 'class' argument.
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=back
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package Biblio::Biblio; |
59
|
2
|
|
|
2
|
|
28103
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
60
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# for debug: |
63
|
2
|
|
|
2
|
|
2392
|
use Data::Dumper; |
|
2
|
|
|
|
|
20828
|
|
|
2
|
|
|
|
|
161
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
BEGIN { |
66
|
2
|
|
|
2
|
|
16
|
use vars qw($Revision $VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
272
|
|
67
|
2
|
50
|
|
2
|
|
4
|
my $major = 1; q$Revision: 13 $ =~ /: (\d+)/; my ($minor) = ($1); $VERSION = "$major." . ($minor<10 ? '0' : '') . $minor;
|
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
42
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
909
|
|
71
|
|
|
|
|
|
|
#use Getopt::Long; |
72
|
|
|
|
|
|
|
#use Text::ParseWords; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# that's cool! |
77
|
|
|
|
|
|
|
# if( 0 ) { |
78
|
|
|
|
|
|
|
# if (defined $ENV{"PERLDOC"}) { |
79
|
|
|
|
|
|
|
# require Text::ParseWords; |
80
|
|
|
|
|
|
|
# unshift(@ARGV, Text::ParseWords::shellwords($ENV{"PERLDOC"})); |
81
|
|
|
|
|
|
|
# } |
82
|
|
|
|
|
|
|
# } |
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item my $bib = new Biblio::Biblio(I)
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Factory method for concrete database implementations.
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Supported Options:
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item class
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Class name. If one of the options file, dbname, dsn, or dbms is specified, it is set automatically to Bibilio::File or Biblio::Database.
|
103
|
|
|
|
|
|
|
If the class name does not contain a '::' the classname is prefixed with 'Biblio::'.
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item file
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Filename in bibtex, refer or any other supported format.
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item dbms
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Name of database type, e.g. ODBC or mysql. This is in fact DBI's dbms argument.
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item dbhost
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Hostname. Passed to DBI.
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item dbname
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Name of the database. Passed to DBI.
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item dbuser, dbpass
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
User and password. Passed to DBI.
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item dsn
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
You can directly specify a DSN that is passed to DBI.
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item B
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Be more verbose and keep the verbose flag within the options.
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Be more quite and keep the quiet flag within the options.
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item I
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Depending on the Biblio class used, other arguments can be specified here.
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
In addition, some arguments can be specified in the environment:
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item 'class' => 'BIBLIO_CLASS'
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item 'file' => 'BIBLIO_FILE'
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item 'dbms' => 'BIBLIO_DBMS'
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item 'dbhost' => 'BIBLIO_HOST'
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item 'dbname' => 'BIBLIO_NAME'
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item 'dbuser' => 'BIBLIO_USER'
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item 'dbpass' => 'BIBLIO_PASS' |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub new { |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# open biblio source |
168
|
|
|
|
|
|
|
# |
169
|
2
|
|
|
2
|
1
|
940
|
my $class = shift; # Just discard it, not used afterwards. |
170
|
2
|
|
|
|
|
10
|
my %args = (defaultArgs(), environmentArgs(), @_); |
171
|
2
|
50
|
33
|
|
|
14
|
print Dumper \%args if $args{'verbose'} && $args{'verbose'} > 1; |
172
|
2
|
|
|
|
|
5
|
$class = $args{'class'}; |
173
|
2
|
50
|
33
|
|
|
10
|
if( defined $class && $class !~ /::/ ) { |
174
|
0
|
|
|
|
|
0
|
$class = "Biblio::$class"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# default rules for fining the class |
178
|
2
|
50
|
33
|
|
|
19
|
if( !defined($class) && defined($args{'file'}) ) { |
179
|
2
|
|
|
|
|
5
|
$class = 'Biblio::File'; |
180
|
|
|
|
|
|
|
} |
181
|
2
|
0
|
0
|
|
|
8
|
if( !defined($class) && |
|
|
|
33
|
|
|
|
|
182
|
|
|
|
|
|
|
(defined($args{'dbname'}) || |
183
|
|
|
|
|
|
|
defined($args{'dsn'}) || |
184
|
|
|
|
|
|
|
defined($args{'dbms'})) ) { |
185
|
0
|
|
|
|
|
0
|
$class = 'Biblio::Database'; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
2
|
50
|
|
|
|
7
|
return undef unless $class; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
#print ("use $class; \$${class}::VERSION\n"); |
191
|
2
|
|
|
2
|
|
1406
|
my $version = eval("use $class; \$${class}::VERSION"); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
48
|
|
|
2
|
|
|
|
|
259
|
|
192
|
2
|
50
|
|
|
|
10
|
unless( defined($version) ) { |
193
|
0
|
|
|
|
|
0
|
croak "Failed to open module $class\n"; |
194
|
|
|
|
|
|
|
} |
195
|
2
|
50
|
|
|
|
11
|
print STDERR "Using $class version $version\n" if $args{'verbose'}; |
196
|
|
|
|
|
|
|
|
197
|
2
|
|
|
|
|
12
|
return new $class(%args); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# |
201
|
|
|
|
|
|
|
# |
202
|
|
|
|
|
|
|
# configuration |
203
|
|
|
|
|
|
|
# |
204
|
|
|
|
|
|
|
# |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub defaultArgs { |
207
|
|
|
|
|
|
|
return ( |
208
|
|
|
|
|
|
|
# 'class' => 'Database', |
209
|
|
|
|
|
|
|
# 'dbname' => 'biblio', |
210
|
|
|
|
|
|
|
# 'dbuser' => 'biblio', |
211
|
|
|
|
|
|
|
# 'dbpass' => 'biblio', |
212
|
2
|
|
|
2
|
0
|
10
|
); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub environmentArgs { |
217
|
|
|
|
|
|
|
# |
218
|
|
|
|
|
|
|
# check environment for arguments |
219
|
|
|
|
|
|
|
# |
220
|
2
|
|
|
2
|
0
|
28
|
my %envargs = ( |
221
|
|
|
|
|
|
|
'class' => $ENV{'BIBLIO_CLASS'}, |
222
|
|
|
|
|
|
|
'dbms' => $ENV{'BIBLIO_DBMS'}, |
223
|
|
|
|
|
|
|
'dbhost' => $ENV{'BIBLIO_HOST'}, |
224
|
|
|
|
|
|
|
'dbname' => $ENV{'BIBLIO_NAME'}, |
225
|
|
|
|
|
|
|
'dbuser' => $ENV{'BIBLIO_USER'}, |
226
|
|
|
|
|
|
|
'dbpass' => $ENV{'BIBLIO_PASS'}, |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
'file' => $ENV{'BIBLIO_FILE'}, |
229
|
|
|
|
|
|
|
); |
230
|
2
|
|
|
|
|
4
|
my ($k, $v); while (($k, $v) = each(%envargs)) { |
|
2
|
|
|
|
|
13
|
|
231
|
14
|
50
|
|
|
|
47
|
delete $envargs{$k} unless defined($v) |
232
|
|
|
|
|
|
|
} |
233
|
2
|
|
|
|
|
13
|
return %envargs; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__
|