| Net-FluidDB documentation | Contained in the Net-FluidDB distribution. |
Net::FluidDB::Tag - FluidDB tags
use Net::FluidDB::Tag;
# create
$tag = Net::FluidDB::Tag->new(
fdb => $fdb,
description => $description,
indexed => 1,
path => $path
);
$tag->create;
# get, optionally fetching descrition
$tag = Net::FluidDB::Tag->get($fdb, $path, description => 1);
$tag->namespace;
# update
$tag->description($new_description);
$tag->update;
# delete
$tag->delete;
Net::FluidDB::Tag models FluidDB tags.
Net::FluidDB::Tag is a subclass of Net::FluidDB::Base.
Net::FluidDB::Tag consumes the roles Net::FluidDB::HasObject, and Net::FluidDB::HasPath.
Constructs a new tag. The constructor accepts these parameters:
An instance of Net::FluidDB.
A description of this tag.
A flag that tells FluidDB whether this tag should be indexed.
The namespace you want to put this tag into. An instance of Net::FluidDB::Namespace representing an existing namespace in FluidDB.
The name of the tag, which is the rightmost segment of its path. The name of "fxn/rating" is "rating".
The path of the tag, for example "fxn/rating".
The description attribute is not required because FluidDB allows fetching tags
without their description. It must be defined when creating or updating tags though.
The attributes namespace, path, and name are mutually dependent. Ultimately
tag creation has to be able to send the path of the namespace and the name of the tag
to FluidDB. So you can set namespace and name, or just path.
This constructor is only useful for creating new tags in FluidDB. Existing tags are
fetched with get.
Retrieves the tag with path $path from FluidDB. Options are:
Tells get whether you want to fetch the description.
Net::FluidDB provides a convenience shortcut for this method.
Determines whether $path1 and $path2 are the same in FluidDB. The basic
rule is that the username fragment is case-insensitive, and the rest is not.
Creates the tag in FluidDB.
Updates the tag in FluidDB. Only the description can be modified.
Deletes the tag in FluidDB.
Gets/sets the description of the tag.
Note that you need to set the description flag when you fetch a
tag for this attribute to be initialized.
A flag, indicates whether this tag is indexed in FluidDB.
The namespace the tag belongs to, as an instance of Net::FluidDB::Namespace. This attribute is lazy loaded.
The name of the tag.
The path of the tag.
http://doc.fluidinfo.com/fluidDB/api/namespaces-and-tags.html
Xavier Noria (FXN), <fxn@cpan.org>
Copyright (C) 2009-2011 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.
| Net-FluidDB documentation | Contained in the Net-FluidDB distribution. |
package Net::FluidDB::Tag; use Moose; extends 'Net::FluidDB::Base'; use Net::FluidDB::Namespace; has description => (is => 'rw', isa => 'Str'); has indexed => (is => 'ro', isa => 'Bool', required => 1); has namespace => (is => 'ro', isa => 'Net::FluidDB::Namespace', lazy_build => 1); with 'Net::FluidDB::HasObject', 'Net::FluidDB::HasPath'; our %FULL_GET_FLAGS = ( description => 1 ); sub _build_namespace { # TODO: add croaks for dependencies my $self = shift; Net::FluidDB::Namespace->get( $self->fdb, $self->path_of_parent, %Net::FluidDB::Namespace::FULL_GET_FLAGS ); } sub parent { shift->namespace; } sub create { my $self = shift; my $payload = $self->json->encode({ description => $self->description, indexed => $self->as_json_boolean($self->indexed), name => $self->name }); $self->fdb->post( path => $self->abs_path('tags', $self->path_of_parent), headers => $self->fdb->headers_for_json, payload => $payload, on_success => sub { my $response = shift; my $h = $self->json->decode($response->content); $self->_set_object_id($h->{id}); } ); } sub get { my ($class, $fdb, $path, %opts) = @_; $opts{returnDescription} = $class->true if delete $opts{description}; $fdb->get( path => $class->abs_path('tags', $path), query => \%opts, headers => $fdb->accept_header_for_json, on_success => sub { my $response = shift; my $h = $class->json->decode($response->content); my $t = $class->new(fdb => $fdb, path => $path, %$h); $t->_set_object_id($h->{id}); $t; } ); } sub update { my $self = shift; my $payload = $self->json->encode({description => $self->description}); $self->fdb->put( path => $self->abs_path('tags', $self->path), headers => $self->fdb->headers_for_json, payload => $payload ); } sub delete { my $self = shift; $self->fdb->delete(path => $self->abs_path('tags', $self->path)); } no Moose; __PACKAGE__->meta->make_immutable; 1; __END__