GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CouchDB::View::Document(3) User Contributed Perl Documentation CouchDB::View::Document(3)

CouchDB::View::Document - CouchDB design document abstraction

  my $doc = CouchDB::View::Document->new({
    _id => "_design/mystuff",
    views => {
      by_name => sub {
        my ($doc) = @_;
        dmap($doc->name, $doc);
      },
      by_whatsit => sub {
        my ($doc) = @_;
        require Whatsit::Parser;
        dmap(Whatsit::Parser->parse($doc), $doc);
      },
    },
  });

  # use with a hypothetical client
  $couchdb_client->put(
    '/mydatabase/' . $doc->uri_id,
    $doc->as_json,
  );

CouchDB::View::Document provides a Perlish interface to creating CouchDB views <http://wiki.apache.org/couchdb/HttpViewApi>. It uses Data::Dump::Streamer to serialize coderefs, which are deserialized and used by CouchDB::View::Server.

Read the CouchDB wiki page on views <http://wiki.apache.org/couchdb/Views> if you have not already. Only Perl specifics will be mentioned here.

The "map" function is already used in Perl. Instead, use "dmap()" (as in the "SYNOPSIS") to map keys to values.

Perl does not have "null". Use "undef".

All the limitations of Data::Dump::Streamer apply to your view functions. In particular, if they use external modules, they will need to "require" or "use" them explicitly (see the Whatsit::Parser example in the "SYNOPSIS"). Likewise, closed-over variables will be dumped, but external named subroutines will not, so this won't work:

  sub elide {
    my $str = shift;
    $str =~ s/^(.{10}).+/$1.../;
    return $str;
  }

  my $doc = CouchDB::View::Document->new({
    ...
    views => {
      elided => sub {
        dmap(elide($doc->{title}), $doc);
      }
    },
  });

The definition of "elide" is not transferred to the view server.

  my $doc = CouchDB::View::Document->new(\%arg);

Create a new design document. See the CouchDB view API <http://wiki.apache.org/couchdb/HttpViewApi> for the details of "\%arg", though "language" is ignored (always 'text/perl').

  print $doc->as_json;

Use "as_hash" (below) and JSON::XS to encode the result. This is suitable for passing directly to a PUT to CouchDB.

  print $doc->uri_id;
  # '_design%2Fmyview'

Convenience method for the document name, since '/' must be escaped.

  print Dumper($doc->as_hash);

Return a hashref suitable for serializing to JSON, including serialized coderefs.

This method is called with a coderef and is expected to return a serialized representation of it. You probably don't need to use this unless you're subclassing CouchDB::View::Document.

CouchDB::View::Server CouchDB::View
2008-05-17 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.