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


Manual Reference Pages  -  COUCHDB::VIEW::DOCUMENT (3)

.ds Aq ’

NAME

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

CONTENTS

SYNOPSIS



  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,
  );



DESCRIPTION

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.

WRITING VIEWS

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.

METHODS

    new



  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’).

    as_json



  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.

    uri_id



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



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

    as_hash



  print Dumper($doc->as_hash);



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

    code_to_string

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.

SEE ALSO

CouchDB::View::Server CouchDB::View
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 COUCHDB::VIEW::DOCUMENT (3) 2008-05-17

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