MongoDBx::Class::ParsedAttribute(3) A Moose role for automatically expanded and collapsed document attributes.


version 1.030002


# in MyApp/ParsedAttribute/
package MyApp::ParsedAttribute::URI;
use Moose;
use namespace::autoclean;
use URI;
with 'MongoDBx::Class::ParsedAttribute';
sub expand {
my ($self, $uri_text) = @_;
return URI->new($uri_text);
sub collapse {
my ($self, $uri_obj) = @_;
return $uri_obj->as_string;
# in MyApp/Schema/
has 'url' => (is => 'ro', isa => 'URI', traits => ['Parsed'], parser => 'MyApp::ParsedAttribute::URI', required => 1);


This module is a Moose role meant to be consumed by classes that automatically expand (from a MongoDB database) and collapse (to a MongoDB database) attributes of a certain type. This is similar to DBIx::Class' InflateColumn family of modules that do pretty much the same thing for the SQL world.

A class implementing this role with a name such as 'URI' (full package name MongoDBx::Class::ParsedAttribute::URI or MyApp::ParsedAttribute::URI) is expected to expand and collapse URI objects. Similarly, a class named 'NetAddr::IP' is expected to handle NetAddr::IP objects.

Currently, a DateTime parser is provided with the MongoDBx::Class distribution.


Consuming classes must implement the following methods:

expand( $value )

Receives a raw attribute's value from a MongoDB document and returns the appropriate object representing it. For example, supposing the value is an epoch integer, the expand method might return a DateTime object.

collapse( $object )

Receives an object representing a parsed attribute, and returns that objects value in a form that can be saved in the database. For example, if the object is a DateTime object, this method might return the date's epoch integer.


Ido Perlmuter, "<ido at>"


Please report any bugs or feature requests to "bug-mongodbx-class at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

        perldoc MongoDBx::Class::ParsedAttribute

You can also look for information at:


Copyright 2010-2014 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 by the Free Software Foundation; or the Artistic License.

See for more information.