File Coverage

blib/lib/Biblio/bp/lib/bp-p-stdbib.pl
Criterion Covered Total %
statement 11 37 29.7
branch 3 16 18.7
condition n/a
subroutine 2 16 12.5
pod n/a
total 16 69 23.1


line stmt bran cond sub pod time code
1             #
2             # bibliography package for Perl
3             #
4             # standard routines for functions
5             #
6             # Dana Jacobsen (dana@acm.org)
7             # 14 January 1995 (last modified 21 Jan 1996)
8              
9             ######
10             # Standard routines bibliography functions. If a format doesn't register
11             # its own function, this is what gets used. It could also specifically
12             # request one of these functions.
13             #
14             # open, close, write, and clear are pretty generic, and I expect
15             # that a lot of formats will just use these.
16             #
17             # read is a little bit more complicated, so may be specifically implemented
18             # in a lot of formats.
19             #
20             # explode, implode, tocanon, and fromcanon are empty functions that return
21             # an 'unsupported' error.
22             #
23             # NOTE that these functions are not meant to be exported -- i.e. you should
24             # not be referring to these anywhere. They should be put in place by the
25             # format registry process.
26              
27             # We can expect that the variable $bib'glb_current_fmt has the name of the
28             # format in it. I suppose we could alternatively pass it in to every
29             # function, but that's pretty ugly, and a lot of routines don't need to know
30             # that. After all, inside format code you should know what your own name is!
31             #
32             # We also use the variable $bib'glb_current_fh as the filehandle to use.
33              
34             sub open_stdbib {
35 139     139   271 local($file) = @_;
36              
37 139 50       278 &panic("open_stdbib called with no arguments") unless defined $file;
38              
39 139         509 &debugs("opening $file<$glb_current_fmt> ($glb_current_fh)", 128, 'module');
40              
41 139 50       1694 return $glb_current_fmt if CORE::open($glb_current_fh, $file);
42              
43 0         0 &goterror("Can't open file $file");
44             }
45              
46             ######
47              
48             sub close_stdbib {
49 2     2   7 local($file) = @_;
50              
51 2 50       8 &panic("close_stdbib called with no arguments") unless defined $file;
52              
53 2         13 &debugs("clearing format $glb_current_fmt information on $file", 128);
54 2         8 $func = $formats{$glb_current_fmt, "clear"};
55 2         12 &$func($file);
56              
57 2         13 &debugs("closing $file<$glb_current_fmt>", 128);
58              
59 2         92 CORE::close($glb_current_fh);
60             }
61              
62             ######
63              
64             # XXXXX We ought to have another read routine that handles those formats
65             # that have no well defined end-of-record. So we read until we reach
66             # the next beginning of record (regex stored in an assoc array by file)
67             # and then save that for the next read (again by file).
68             # This would be good to implement once so nobody is tempted to write
69             # it themselves and do it wrong.
70              
71             sub read_stdbib {
72 0     0     local($file) = @_;
73              
74 0 0         &debugs("reading $file<$glb_current_fmt>", 32) if $glb_debug;
75              
76             # read a paragraph
77 0           local($/) = '';
78 0           scalar(<$glb_current_fh>);
79             }
80              
81             ######
82              
83             sub write_stdbib {
84 0     0     local($file, $out) = @_;
85 0           local($chopchar);
86              
87 0 0         &panic("write_stdbib called with no arguments") unless defined $file;
88 0 0         &panic("write_stdbib called with no output") unless defined $out;
89              
90 0 0         &debugs("writing $file<$glb_current_fmt>", 32) if $glb_debug;
91              
92             # This is kind of silly, but I want one newline after each record.
93             # Note that the perl5 "chomp" command fixes this annoyance of chop.
94             # XXXXX should this be while(chop($out) eq "\n") or somesuch?
95              
96 0           $chopchar = chop($out);
97 0 0         if ($chopchar eq "\n") {
98 0           print $glb_current_fh ($out, "\n\n");
99             } else {
100 0           print $glb_current_fh ($out, $chopchar, "\n\n");
101             }
102             }
103              
104             ######
105              
106             sub clear_stdbib {
107 0     0     1;
108             }
109              
110             ######
111              
112             sub options_stdbib {
113 0     0     undef;
114             }
115              
116             ######
117              
118             #
119             # I really wish we could define just one function and pass in an argument.
120             # This is a lot of clutter.
121             #
122              
123             # These are the messages for routines not supported.
124              
125             # XXXXX This message is too vague.
126             sub generic_unsup_stdbib {
127 0     0     &bib'goterror("That function is not supported");
128             }
129              
130             sub implode_unsup_stdbib {
131 0     0     &bib'goterror("The $glb_current_fmt format does not support input parsing");
132             }
133              
134             sub explode_unsup_stdbib {
135 0     0     &bib'goterror("The $glb_current_fmt format does not support output parsing");
136             }
137              
138             sub tocanon_unsup_stdbib {
139 0     0     &bib'goterror("The $glb_current_fmt format does not support input conversion");
140             }
141              
142             sub fromcanon_unsup_stdbib {
143 0     0     &bib'goterror("The $glb_current_fmt format does not support output conversion");
144             }
145              
146             # These are for the routines not implemented
147              
148             sub generic_unimpl_stdbib {
149 0     0     &bib'goterror("That function has not yet been implemented");
150             }
151              
152             sub implode_unimpl_stdbib {
153 0     0     &bib'goterror("The $glb_current_fmt format has not yet implemented input parsing");
154             }
155              
156             sub explode_unimpl_stdbib {
157 0     0     &bib'goterror("The $glb_current_fmt format has not yet implemented output parsing");
158             }
159              
160             sub tocanon_unimpl_stdbib {
161 0     0     &bib'goterror("The $glb_current_fmt format has not yet implemented input conversion");
162             }
163              
164             sub fromcanon_unimpl_stdbib {
165 0     0     &bib'goterror("The $glb_current_fmt format has not yet implemented output conversion");
166             }
167              
168             1;