Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the MongoDB CPAN distribution.

Maintainer(s)' notes

Please don't report bugs here. Please use the MongoDB Perl driver issue tracker instead.

Report information
The Basics
Id: 60161
Status: resolved
Priority: 0/
Queue: MongoDB

People
Owner: Nobody in particular
Requestors: admwiggin [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.35
Fixed in: (no value)



Subject: boolean::true and boolean::false are accepted to put boolean values in, but they are not returned to get boolean values back out
To place boolean values "true" and "false" into MongoDB using insert, save, etc., boolean::true and boolean::false can be used. However, when these boolean values are read back out, they are translated into 1 and 0, which are functionally equivalent, but somewhat defeat the purpose of using boolean::true and boolean::false to save the values in the first place. To solve this, I have provided the following patch, which will attempt to call boolean::true or boolean::false appropriately for BSON_BOOL items returned from the database (and if those fail, hopefully fall back on the current behavior). This is my first time writing C to call a Perl function, so comments or suggestions are very much welcome. All I can say is that this is working great for me.
Subject: return-boolean-objects.patch
diff --git perl_mongo.c perl_mongo.c index 88c3e1b..021d30b 100644 --- perl_mongo.c +++ perl_mongo.c @@ -346,7 +346,29 @@ elem_to_sv (int type, buffer *buf) } case BSON_BOOL: { char d = *buf->pos++; - value = newSViv(d); + int count; + dSP; + + SAVETMPS; + + PUSHMARK(SP); + PUTBACK; + if (d) { + count = call_pv("boolean::true", G_SCALAR); + } + else { + count = call_pv("boolean::false", G_SCALAR); + } + SPAGAIN; + if (count == 1) + value = newSVsv(POPs); + + if (count != 1 || !SvOK(value)) { + value = newSViv(d); + } + + PUTBACK; + FREETMPS; break; } case BSON_UNDEF: