New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading from strings or string-based file handles #1
Comments
Yes, I also wished this worked. The problem is that the underlying C library libbtparse doesn't do PerlIO, only stdio since it wasn't written for Perl XS. Opening filehandles on strings is PerlIO only. I did briefly look at making libbtparse PerlIO compliant but it's not so easy. |
One could at least let Text::BibTeX create a temporary file from the string and let libbtparse parse from it. This is a hack but users of a library should not have to care about the design of components two levels down the hierarchy of abstraction. Another solution is to split the string into BibTeX entries by regexp and feed each entry to Text::BibTeX::Entry. |
I agree that this isn't ideal - the problem is that the module was written (by someone else) for perl long before PerlIO even existed so nobody even thought of reading from strings like that. The temporary file this is a decent idea but needs careful though about where to create this across platforms (can't assume current dir is ok) and it means some fairly exciting XS hacking which I'm terrible at. For now, I'd do the temp file thing in your own code. That's what I had to do with writing STDERR from the module too - you can't write it to a variable for the same reason. |
Text::BibTeX::File open method is an interface with IO::File. Therefore, anything you can do with it should be possible to do with Text::BibTeX::File. Nevertheless, I would prefer to have explicitly a Text::BibTeX::File->open_from_string or something. |
Actually, a dedicated string reading method would be best and follows the general interfaces for things like LibXML etc. As I remember having fought with this too, I seem to recall that even though it uses IO::File in the Perl module, the C library is so old, it only uses very basic STDIO and this is the problem because the open methods in the module just pass directly to the library. |
Given that normal lines in all BibTeX files I used so far never begin with
Anyway - the requirement to dig into this makes the whole library less useful for quick scripts. I better use another scripting language or another library next time :-( |
I expected one of this to work:
Perl supports file handles based on string data since long ago.
The text was updated successfully, but these errors were encountered: