Anyone using Berkley XML DB w/Perl (of course)...?

C

Chris

I'm trying to find some Perl API support (read "CPAN module") for using
Sleepcat's Berkley XML DB, but I'm coming up blank. Sleepcat's web site
is Java and C++ centric and I see no Perl information there though an
article I read on XML DB claims there is Perl support. Googling for a
suitable module produced nothing of interest, not to mention such
searching is muddied by www.xmldb.org which uses a lot of Perl-like
"XML::DB" notation.

It would appear that Berkley's XML DB coupled with XML::Dumper poses
some interesting possibilities for run-time object persistence between
client and server platforms... tantalizing to say the least.

Surely I would be spared having to download the Java support and convert
to Perl modules... 8-( I guess I can try their message list, but
thought a quick note here would maybe turn up something solid.

Chris
 
V

Vetle Roeim

* (e-mail address removed)
I'm trying to find some Perl API support (read "CPAN module") for
using Sleepcat's Berkley XML DB, but I'm coming up blank.

You're not going to find it on CPAN, unfortunately. To install it, I
downloaded the source code, compiled it, and then installed the Perl
module from dbxml-1.2.0/src/perl.

Good luck.


[...]
 
R

Robert

Chris said:
I'm trying to find some Perl API support (read "CPAN module") for using
Sleepcat's Berkley XML DB, but I'm coming up blank. Sleepcat's web site
is Java and C++ centric and I see no Perl information there though an
article I read on XML DB claims there is Perl support. Googling for a
suitable module produced nothing of interest, not to mention such
searching is muddied by www.xmldb.org which uses a lot of Perl-like
"XML::DB" notation.

It would appear that Berkley's XML DB coupled with XML::Dumper poses
some interesting possibilities for run-time object persistence between
client and server platforms... tantalizing to say the least.

Surely I would be spared having to download the Java support and convert
to Perl modules... 8-( I guess I can try their message list, but
thought a quick note here would maybe turn up something solid.

Chris
-----

And if someone does create a binary (esp. for ActiveState) please share
it. :)
 
B

Ben Morrow

Vetle Roeim said:
* (e-mail address removed)

You're not going to find it on CPAN, unfortunately. To install it, I
downloaded the source code, compiled it, and then installed the Perl
module from dbxml-1.2.0/src/perl.

Having taken a look at that: bleech. Is it *quite* necessary to
trample on that many different (including top-level and pragmatic)
namespaces? And is it really necessary to have the interface be so
C++ish?

You may be better off writing your own wrapper: it shouldn't be *that*
hard...

Ben
 
C

Chris

Robert said:
And if someone does create a binary (esp. for ActiveState) please share
it. :)

Well, if I combine all the sentiments, it seems that maybe a more
Perl-like wrapper/module could be in order. I doubt I will have the
time to look at it seriously for a little while yet, but I might venture
into it here before too long. It seems there might actually be some
interest in that sort of thing, myself included. And I *was* wanting it
initially for ActiveState in the immediate, even though I tend to prefer
Linux. I'd *really* like to play with this XML DB some... The object
persistence this could bring to some stateless apps would be fun to play
with over and above sessions (CGI::Sessions, etc.).

I'll download the Linux source and follow the lead I was given and see
where that takes me. Should have thought to do that (check out the
Linux source) already.

Thanks all,
Chris
 
V

Vetle Roeim

* Ben Morrow
Having taken a look at that: bleech. Is it *quite* necessary to
trample on that many different (including top-level and pragmatic)
namespaces? And is it really necessary to have the interface be so
C++ish?

I didn't like it either. There exists a set of
XML::DB::Database-modules that provide interfaces to a couple of XML
databases. I haven't checked them out, though.

They may provide a better interface.


[...]
 
P

Paul Marquess

Ben Morrow said:
Having taken a look at that: bleech.

Thanks for the constructive feedback Ben. :)

Seriously though, I'd be interested to hear in a bit more detail what you,
and anoyone else in this thread, think about the current interface, both
good and bad. To date, this is the first negative feedback I've received.
Is it *quite* necessary to
trample on that many different (including top-level and pragmatic)
namespaces?

Yes. There are quite a few objects exposed by the dbxml interface. If you
want those C++ objects to map to Perl objects, you need a namespace for
each.

I didn't think I was reusing any pragmatic namespaces - which are you
thinking of?
And is it really necessary to have the interface be so C++ish?

Well it is an interface to a C++ library after all :)

When I wrote the interface, it seemed obvious make it mirror the OO
interface that dbxml was already provinding.
You may be better off writing your own wrapper: it shouldn't be *that*
hard...

Absolutely, TMTOWTDI.

Paul
 
B

Ben Morrow

Paul Marquess said:
Thanks for the constructive feedback Ben. :)

Sorry, that was a little rude... :(.
Seriously though, I'd be interested to hear in a bit more detail what you,
and anoyone else in this thread, think about the current interface, both
good and bad. To date, this is the first negative feedback I've received.


Yes. There are quite a few objects exposed by the dbxml interface. If you
want those C++ objects to map to Perl objects, you need a namespace for
each.

Yes, but you don't need to give them the same names as the C++ classes
had. What happens if someone's using another XML module as well (not
at all unlikely), and that happened to also define the package
XmlDocument?

Indeed, the C++ classes are all in the namespace DbXml, which will
keep them from conflicting with any other XmlDocument class people
might be using. I would have given the classes names like
DB::XML::Container, and kept all the names below DB::XML, or
something.
I didn't think I was reusing any pragmatic namespaces - which are you
thinking of?

std::exception. All lower-case top-level namespaces are reserved for
pragmata. The whole exception-handling logic seems unnecessarily
complex: what's wrong with

package DB::XML::Exception;

our @EXPORT = qw/catch/;

sub catch {
my $type = shift;
UNIVERSAL::isa($@, __PACKAGE__) and $@->{type} eq $type
and return $@;
return;
}

package main;

eval {
...
}
if (my $e = catch 'DbException') {
...
}

or

if (ref $@ and $a->isa(DB::XML::X::DbDeadlock)) {

or even

if ($@ and $!{EDEADLK}) {

, which I at least find much more Perlish? The mapping seems pretty
clear:

DbDeadlockException EDEADLK
DbException is never thrown
DbLockNotGrantedException EWOULDBLOCK
DbRunRecoveryException EINVAL

etc. XmlException could probably just throw a string.

I realise this means you can't just get the typemap to do all the work
:).
Well it is an interface to a C++ library after all :)

True... your BerkeleyDB module, though, provides a much more Perl-ish
interface to the C db libraries.
Absolutely, TMTOWTDI.

Well, yes :).

Ben
 
P

Paul Marquess

Ben Morrow said:
Sorry, that was a little rude... :(.


Yes, but you don't need to give them the same names as the C++ classes
had.

I assume your issue isn't really that I've used the same names as the C++
classes, but that I've put them in a top-level namespace? Ignoring namespace
issues for a moment, reusing the C++ class names seems to make perfect
sense.
What happens if someone's using another XML module as well (not
at all unlikely), and that happened to also define the package
XmlDocument?

Indeed, the C++ classes are all in the namespace DbXml, which will
keep them from conflicting with any other XmlDocument class people
might be using. I would have given the classes names like
DB::XML::Container, and kept all the names below DB::XML, or
something.

There is always a problem of clashing namespaces, and I accept that by using
quite a few top-level names I'm increasing that possibility. I'm not
convinced
it's as big a problem as you make out, but I'll have a think about this
one - my preferred choice would be to go for DbXml:: as the common prefix
for all the class names.
std::exception. All lower-case top-level namespaces are reserved for
pragmata.

Indeed it is.
The whole exception-handling logic seems unnecessarily
complex: what's wrong with

package DB::XML::Exception;

our @EXPORT = qw/catch/;

sub catch {
my $type = shift;
UNIVERSAL::isa($@, __PACKAGE__) and $@->{type} eq $type
and return $@;
return;
}

package main;

eval {
...
}
if (my $e = catch 'DbException') {
...
}

Ignoring the hoops I may have jumped through to implement my version of
"catch", from an end users point of view, that looks very like what I've
already implemented.

One thing on my todo list is to provide a shortcut to get at the exception
string. I'll probably do it by overloading the stringification operator.

eval {
...
};

if (my $e = catch XmlException) {
print "got this exception $e\n";
}
or

if (ref $@ and $a->isa(DB::XML::X::DbDeadlock)) {

Personally, I hate that syntax in user code, although it should already work
with my current
interface. :)
or even

if ($@ and $!{EDEADLK}) {

, which I at least find much more Perlish? The mapping seems pretty
clear:

DbDeadlockException EDEADLK
DbException is never thrown
DbLockNotGrantedException EWOULDBLOCK
DbRunRecoveryException EINVAL

etc. XmlException could probably just throw a string.

If I was going to go down that route, I'd rip out the exception handling
interface and use return codes instead.
I realise this means you can't just get the typemap to do all the work
:).

Quite so :)
True... your BerkeleyDB module, though, provides a much more Perl-ish
interface to the C db libraries.

I think there are a couple of reasons for the difference in the interfaces
I created. The first is simply down to the fact that the native dbxml
interface is C++, while Berkeley DB is C.

The other reason I've deliberately kept close to the C++ interface was to
future proof myself. The dbxml library is still quite young and has already
changed a couple of times -- I don't want to paint myself into any corner
with interface decisions.

cheers
Paul
 
B

Ben Morrow

Paul Marquess said:
I assume your issue isn't really that I've used the same names as the C++
classes, but that I've put them in a top-level namespace?

Of course.
Ignoring namespace issues for a moment, reusing the C++ class names
seems to make perfect sense.

Well, yes... it depends on who's point of view your coming from. There
are rather different conventions for how things should be named in C++
and Perl (in particular, XML-related and DB-related modules in Perl
*always* spell them XML and DB rather than Xml and Db), so none of
those names would have been invented by someone writing a DBXML
library from scratch in Perl. If you are more concerned that someone
with familiarity with this library in C++ should not be lost when
using it in Perl, then stick to the C++ names. If you are more
concerned that someone used to Perl should not be confused when coming
to this module as a Perl module, with no knowledge of or interest in
the underlying C++ library, then more Perlish names would be better.
There is always a problem of clashing namespaces, and I accept that by using
quite a few top-level names I'm increasing that possibility.

The point of the CPAN namespace-registration system is that it gets
rid of the problem. People register their namespaces, and stay within
them, and then we don't get conflicts. You will note that the PAUSE
module-list registration form specifically says that you must provide
good reasons why you need a new top-level namespace.
I'm not convinced it's as big a problem as you make out,

Are you not? I think that as things stand there may not be much of a
problem, because 1. noone else would use those C++ish names and
2. everyone else will follow the rules and not use top-level names
when they don't need to. I don't think these are good things to rely
on.

As I said, consider someone using some other XML module: say, to get
XML out of their database and insert it into some other system. If the
name XmlDocument were considered fair game, you must admit it's not at
all unlikely that this other module author would have used it as
well. The only way there is any chance of avoiding clashes is if
everyone sticks within their own namespace.
but I'll have a think about this
one - my preferred choice would be to go for DbXml:: as the common prefix
for all the class names.

OK... it doesn't matter what you choose, as long as you choose something.
Ignoring the hoops I may have jumped through to implement my version of
"catch", from an end users point of view, that looks very like what I've
already implemented.

That was the point: it's almost identical, and doesn't stomp on about
6 top-level names.
One thing on my todo list is to provide a shortcut to get at the exception
string. I'll probably do it by overloading the stringification operator.

eval {
...
};

if (my $e = catch XmlException) {
print "got this exception $e\n";
}

Oh, does it not already?... I'd kinda assumed it would :).
Personally, I hate that syntax in user code, although it should
already work with my current interface. :)

Yeah, but it's (one of) the Perl idiom(s) for exception
catching. Someone reading that code will see instantly what it
does. Inventing random new interfaces violates the principle of least
surprise.
If I was going to go down that route, I'd rip out the exception handling
interface and use return codes instead.

Yup.... personally, I'd not object to that. Remember, people can
always put it back with use fatal. One of the things I dislike about
Java (I've never written any (modern) C++) is that everything has to
be wrapped in a try/catch block.
I think there are a couple of reasons for the difference in the interfaces
I created. The first is simply down to the fact that the native dbxml
interface is C++, while Berkeley DB is C.

....yes...? Neither is Perl, despite the superficial similarities
between C++'s and Perl's OO.
The other reason I've deliberately kept close to the C++ interface was to
future proof myself. The dbxml library is still quite young and has already
changed a couple of times -- I don't want to paint myself into any corner
with interface decisions.

This is, of course, sensible. Might I respectfully suggest a strategy
of having a DbXml::Native module that is just a very thin XS wrapper
around the C++ library, and then making DbXml implemented in Perl on
top of that?

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top