Why not adopt me?
NAME
Net::FluidDB::Object - FluidDB objects
SYNOPSIS
use Net::FluidDB::Object;
# create, with optional about
$object = Net::FluidDB::Object->new(
fdb => $fdb,
about => $unique_about
);
$object->create;
$object->id; # returns the object's ID in FluidDB
# get by ID, optionally fetching about
$object = Net::FluidDB::Object->get($fdb, $object_id, about => 1);
# tag
$object->tag("fxn/likes");
$object->tag("fxn/rating", 10, fdb_type => 'integer');
$object->tag("fxn/avatar", $image, mime_type => 'image/png');
# retrieve a tag value
$value = $object->("fxn/rating");
# search
@ids = Net::FluidDB::Object->search($fdb, "has fxn/rating");
DESCRIPTION
Net::FluidDB::Object
models FluidDB objects.
USAGE
Inheritance
Net::FluidDB::Object
is a subclass of Net::FluidDB::Base.
Class methods
- Net::FluidDB::Object->new(%attrs)
-
Constructs a new object. The constructor accepts these parameters:
This constructor is only useful for creating new objects in FluidDB. Already existing objects are fetched with
get
. - Net::FluidDB::Object->get($fdb, $id, %opts)
-
Retrieves the object with ID
$id
from FluidDB. Options are:- about (optional, default false)
-
Tells
get
whether you want to get the about attribute of the object.If about is not fetched
has_about
will be false even if the object has an about attribute in FluidDB.
Net::FluidDB
provides a convenience shortcut for this method. - Net::FluidDB::Object->search($fdb, $query)
-
Performs the query
$query
and returns a (possibly empty) array of strings with the IDs of the macthing objects.Net::FluidDB
provides a convenience shortcut for this method.
Instance Methods
- $object->create
-
Creates the object in FluidDB.
- $object->id
-
Returns the UUID of the object, or
undef
if it is new. - $object->has_id
-
Predicate to test whether the object has an ID.
- $object->about
- $object->about($about)
-
Gets/sets the about attribute. About can't be modified in existing objects, the setter is only useful for new objects.
Note that you need to set the
about
flag when you fetch an object for this attribute to be initialized. - $object->has_about
-
Says whether the object has an about attribute.
Note that you need to set the
about
flag when you fetch an object for this attribute to be initialized. - $object->tag_paths
-
Returns the paths of the existing tags on the object as a (possibly empty) arrayref of strings.
- $object->tag($tag_or_tag_path, $value, %options)
-
Tags an object.
You can pass either a Net::FluidDB::Tag instance instance or a tag path in the first argument. Tag values may be native or non-native.
- Tagging with Net::FluidDB::Values
-
This method accepts Net::FluidDB::Values, in which case no options are needed, but offers a convenience interface to be able to work with plain scalars, see the next item.
- Tagging with ordinary scalars
-
Tagging with ordinary scalars has two interfaces, one for native values, and one for non-native values.
- Native values
-
For native value you need to pass a
fdb_type
option to indicate its FluidDB type. One of "null", "boolean", "integer", "float", "string", or "set".$object->tag("fxn/rating", 10, fdb_type => 'integer');
If
$value
isundef
or an arrayref this is not required:$object->tag("fxn/tags"); # type null $object->tag("fxn/tags", undef); # type null $object->tag("fxn/tags", ["perl", "moose"]); # type set
- Non-native values
-
To tag with a non-native value you need to pass a
mime_type
option with a suitable MIME type for it:$object->tag("fxn/foaf", $foaf, mime_type => "application/rdf+xml");
- $object->value($tag_or_tag_path)
-
Gets the value of a tag on an object.
You can refer to the tag either with a Net::FluidDB::Tag instance or a tag path.
The returned value is an instance of some child of Net::FluidDB::Value. The
value
method returns the actual scalar value:$value = $object->value("fxn/rating"); print $value->value;
This object may be inspected: Any value responds to
$value->is_native; $value->is_non_native;
Native values have predicates:
$value->is_null; $value->is_boolean; $value->is_integer; $value->is_float; $value->is_string; $value->is_set;
The MIME type of a non-native value is also available:
$value->mime_type;
FLUIDDB DOCUMENTATION
AUTHOR
Xavier Noria (FXN), <fxn@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2009 Xavier Noria
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 http://dev.perl.org/licenses/ for more information.