Permalink
Browse files

added TO_JSON method to Mango::BSON::Binary

  • Loading branch information...
1 parent e99d112 commit 5f3ea63a5e783cc2fe81d6207d8e18d294dff60b @kraih committed Feb 24, 2013
Showing with 9 additions and 0 deletions.
  1. +1 −0 Changes
  2. +4 −0 lib/Mango/BSON/Binary.pm
  3. +4 −0 t/bson.t
View
@@ -3,6 +3,7 @@
- Added drop_index, index_information and stats methods to
Mango::Collection.
- Added eval and stats methods to Mango::Database.
+ - Added TO_JSON method to Mango::BSON::Binary.
- Added TO_JSON method to Mango::BSON::Time.
- Improved exception handling for commands.
- Improved documentation.
View
@@ -2,8 +2,12 @@ package Mango::BSON::Binary;
use Mojo::Base -base;
use overload '""' => sub { shift->data }, fallback => 1;
+use Mojo::Util 'b64_encode';
+
has [qw(data type)];
+sub TO_JSON { b64_encode shift->data, '' }
+
1;
=head1 NAME
View
@@ -300,4 +300,8 @@ is_deeply bson_decode(bson_encode({false => \$bytes})), {false => bson_false},
is j({time => bson_time(1360626536748)}), '{"time":1360626536748}',
'right JSON';
+# Binary to JSON
+is j({bin => bson_bin('Hello World!')}), '{"bin":"SGVsbG8gV29ybGQh"}',
+ 'right JSON';
+
done_testing();

0 comments on commit 5f3ea63

Please sign in to comment.