Permalink
Browse files

fixed bug causing MongoDBx::Class to fail when a document class has a…

…ttributes that hold blessed values of classes that do not use Moose.
  • Loading branch information...
1 parent b7b62bf commit 0cd46701c812067d7f84a31a93e17f1776312893 Ido Perlmuter committed May 1, 2011
View
1 .gitignore
@@ -12,3 +12,4 @@ pm_to_blib*
cover_db
pod2htm*.tmp
MongoDBx-Class-*
+.build*
View
3 Changes
@@ -1,6 +1,9 @@
Revision history for MongoDBx::Class
{{$NEXT}}
+ - Fixed bug causing MongoDBx::Class to fail when a document class
+ has attributes that hold blessed values of classes that do not
+ use Moose.
0.7 2011-03-17 00:48:50 Asia/Jerusalem
- Changed the way database connection is made to be more like
View
1 MANIFEST.SKIP
@@ -13,3 +13,4 @@
^cover_db$
^pod2htm.*\.tmp$
^MongoDBx-Class-.*$
+^\.build.+$
View
24 README
@@ -8,13 +8,13 @@ SYNOPSIS
my $dbx = MongoDBx::Class->new(namespace => 'MyApp::Model::DB');
# connect to a MongoDB server
- $dbx->connect(host => 'localhost', port => 27017);
+ my $conn = $dbx->connect(host => 'localhost', port => 27017);
# be safe by default
- $dbx->conn->safe(1); # we could've also just passed "safe => 1" to $dbx->connect() above
+ $conn->safe(1); # we could've also just passed "safe => 1" to $dbx->connect() above
# get a MongoDB database
- my $db = $dbx->conn->get_database('people');
+ my $db = $conn->get_database('people');
# insert a person
my $person = $db->insert({ name => 'Some Guy', birth_date => '1984-06-12', _class => 'Person' });
@@ -26,7 +26,8 @@ SYNOPSIS
$person->delete;
DESCRIPTION
- WARNING: THIS IS ALPHA SOFTWARE.
+ WARNING: MongoDBx::Class is still in beta status. Please do not rely on
+ it yet for production use.
MongoDBx::Class is a flexible object relational mapper (ORM) for MongoDB
databases. Given a schema-like collection of document classes,
@@ -160,11 +161,6 @@ ATTRIBUTES
be descendants of this namespace (e.g. "MyApp::Schema::Article",
"MyApp::Schema::Post").
- conn
- The object's connection to a MongoDB server. This is a
- MongoDBx::Class::Connection object (which extends MongoDB::Connection).
- This is set only after the "connect()" method is called.
-
doc_classes
A hash-ref of document classes found when loading the schema.
@@ -182,8 +178,12 @@ OBJECT METHODS
attribute from MongoDBx::Class::Connection. You're mostly expected to
provide the 'host' and 'port' options. If a host is not provided,
'localhost' is used. If a port is not provided, 27017 (MongoDB's default
- port) is used. The created MongoDBx::Class::Connection object is
- returned and also saved as the calling object's 'conn' attribute.
+ port) is used. Returns a MongoDBx::Class::Connection object.
+
+ NOTE: Since version 0.7, the created connection object isn't saved in
+ the top MongoDBx::Class object, but only returned, in order to be more
+ like how connection is made in MongoDB (and to allow multiple
+ connections). This change breaks backwords compatibility.
INTERNAL METHODS
The following methods are only to be used internally.
@@ -249,7 +249,7 @@ ACKNOWLEDGEMENTS
in writing MongoDBx::Class.
LICENSE AND COPYRIGHT
- Copyright 2010 Ido Perlmuter.
+ Copyright 2010-2011 Ido Perlmuter.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
View
5 dist.ini
@@ -1,9 +1,6 @@
name = MongoDBx-Class
-version = 0.7
author = Ido Perlmuter <ido@ido50.net>
license = Perl_5
copyright_holder = Ido Perlmuter
-[@Filter]
--bundle = @IDOPEREL
--remove = LatestPrereqs
+[@IDOPEREL]
View
3 lib/MongoDBx/Class.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class;
# ABSTRACT: Flexible ORM for MongoDB databases
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use Moose::Util::TypeConstraints;
use namespace::autoclean;
View
3 lib/MongoDBx/Class/Collection.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Collection;
# ABSTRACT: A MongoDBx::Class collection object
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;
use Carp;
View
19 lib/MongoDBx/Class/Connection.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Connection;
# ABSTARCT: A connection to a MongoDB server
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;
use Module::Load;
@@ -209,7 +212,7 @@ sub expand {
$attrs{$_->name} = $self->expand($coll_ns, $doc->{$_->name});
}
# is this an expanded attribute?
- } elsif ($_->does('MongoDBx::Class::Meta::AttributeTraits::Parsed') && $_->parser) {
+ } elsif ($_->can('does') && $_->does('MongoDBx::Class::Meta::AttributeTraits::Parsed') && $_->parser) {
next unless exists $doc->{$_->name} && defined $doc->{$_->name};
load $_->parser;
my $val = $_->parser->new->expand($doc->{$_->name});
@@ -257,7 +260,7 @@ sub collapse {
next if $_ eq '_class';
my $attr = $dc->meta->get_attribute($_);
- if ($attr && $attr->does('MongoDBx::Class::Meta::AttributeTraits::Parsed') && $attr->parser) {
+ if ($attr && $attr->can('does') && $attr->does('MongoDBx::Class::Meta::AttributeTraits::Parsed') && $attr->parser) {
load $attr->parser;
my $parser = $attr->parser->new;
if (ref $doc->{$_} eq 'ARRAY') {
@@ -288,18 +291,18 @@ sub _collapse_val {
if (blessed $val && $val->isa('MongoDBx::Class::Reference')) {
return { '$ref' => $val->ref_coll, '$id' => $val->ref_id };
- } elsif (blessed $val && $val->does('MongoDBx::Class::Document')) {
+ } elsif (blessed $val && $val->can('does') && $val->does('MongoDBx::Class::Document')) {
return { '$ref' => $val->_collection->name, '$id' => $val->_id };
- } elsif (blessed $val && $val->does('MongoDBx::Class::EmbeddedDocument')) {
+ } elsif (blessed $val && $val->can('does') && $val->does('MongoDBx::Class::EmbeddedDocument')) {
return $val->as_hashref;
} elsif (ref $val eq 'ARRAY') {
my @arr;
foreach (@$val) {
if (blessed $_ && $_->isa('MongoDBx::Class::Reference')) {
push(@arr, { '$ref' => $_->ref_coll, '$id' => $_->ref_id });
- } elsif (blessed $_ && $_->does('MongoDBx::Class::Document')) {
+ } elsif (blessed $_ && $_->can('does') && $_->does('MongoDBx::Class::Document')) {
push(@arr, { '$ref' => $_->_collection->name, '$id' => $_->_id });
- } elsif (blessed $_ && $_->does('MongoDBx::Class::EmbeddedDocument')) {
+ } elsif (blessed $_ && $_->can('does') && $_->does('MongoDBx::Class::EmbeddedDocument')) {
push(@arr, $_->as_hashref);
} else {
push(@arr, $_);
@@ -311,9 +314,9 @@ sub _collapse_val {
foreach (keys %$val) {
if (blessed $val->{$_} && $val->{$_}->isa('MongoDBx::Class::Reference')) {
$h->{$_} = { '$ref' => $val->{$_}->ref_coll, '$id' => $val->{$_}->ref_id };
- } elsif (blessed $val->{$_} && $val->{$_}->does('MongoDBx::Class::Document')) {
+ } elsif (blessed $val->{$_} && $_->can('does') && $val->{$_}->does('MongoDBx::Class::Document')) {
$h->{$_} = { '$ref' => $val->{$_}->_collection->name, '$id' => $val->{$_}->_id };
- } elsif (blessed $val->{$_} && $val->{$_}->does('MongoDBx::Class::EmbeddedDocument')) {
+ } elsif (blessed $val->{$_} && $_->can('does') && $val->{$_}->does('MongoDBx::Class::EmbeddedDocument')) {
$h->{$_} = $val->{$_}->as_hashref;
} else {
$h->{$_} = $val->{$_};
View
3 lib/MongoDBx/Class/Cursor.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Cursor;
# ABSTRACT: A MongoDBx::Class cursor/iterator object for query results
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;
View
3 lib/MongoDBx/Class/Database.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Database;
# ABSTRACT: A MongoDBx::Class database object
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;
View
3 lib/MongoDBx/Class/Document.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Document;
# ABSTRACT: A MongoDBx::Class document role
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose::Role;
use namespace::autoclean;
use Carp;
View
3 lib/MongoDBx/Class/EmbeddedDocument.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::EmbeddedDocument;
# ABSTRACT: A MongoDBx::Class embedded (sub-)document role
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose::Role;
use namespace::autoclean;
View
6 lib/MongoDBx/Class/Meta/AttributeTraits.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Meta::AttributeTraits;
# ABSTRACT: Attribute traits provided by MongoDBx::Class
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
=head1 NAME
MongoDBx::Class::Meta::AttributeTraits - Attribute traits provided by MongoDBx::Class
@@ -12,6 +15,9 @@ package MongoDBx::Class::Meta::AttributeTraits::Parsed;
# ABSTRACT: An attribute trait for attributes automatically expanded and collapsed by a parser class.
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose::Role;
use namespace::autoclean;
View
3 lib/MongoDBx/Class/Moose.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Moose;
# ABSTRACT: Extends Moose with common relationships for MongoDBx::Class documents
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose ();
use Moose::Exporter;
View
3 lib/MongoDBx/Class/ParsedAttribute.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::ParsedAttribute;
# ABSTRACT: A Moose role for automatically expanded and collapsed document attributes.
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose::Role;
use namespace::autoclean;
View
3 lib/MongoDBx/Class/ParsedAttribute/DateTime.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::ParsedAttribute::DateTime;
# ABSTRACT: An automatic DateTime parser for MongoDBx::Class document classes
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;
use DateTime::Format::W3CDTF;
View
3 lib/MongoDBx/Class/Reference.pm
@@ -2,6 +2,9 @@ package MongoDBx::Class::Reference;
# ABSTRACT: An embedded document representing a reference to a different document (thus establishing a relationship)
+our $VERSION = "0.7001";
+$VERSION = eval $VERSION;
+
use Moose;
use namespace::autoclean;

0 comments on commit 0cd4670

Please sign in to comment.