The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Persevere::Client - A Simple to use Interface to Persevere the JSON Database

VERSION

Version 0.31

SYNOPSIS

This module Is a simple interface to Persevere, the JSON Database.

This module provides an interface similar to that of Couchdb::Client

View documentation on Persevere::Client::Class for information on how to interact with Persevere Classes.

use Persevere::Client;

  my $persvr = Persevere::Client->new(
    host => "localhost",
    port => "8080",
    auth_type => "basic",
    username => "user", 
    password => "pass"  
  );

  die "Unable to connect to $persvr->{uri}\n" if !($persvr->testConnection);
  my $status;
  my $statusreq = $persvr->serverInfo;
  if ($statusreq->{success}){
      $status = $statusreq->{data};
  }
  print "VM: $status->{vm}\nVersion: $status->{version}\n";
  print "Class File Exists\n" if $persvr->classExists("File");
  print "Class Garbage Doesn't Exist\n" if (!($persvr->classExists("garbage")));
  my @class_list;
  my $classreq = $persvr->listClassNames;
  if ($classreq->{success}){
      @class_list = @{$classreq->{data}};
  }

MEATHODS

new

Constructor

uri - Takes a hash or hashref of options: uri which specifies the server's URI; scheme, host, port which are used if uri isn't provided and default to 'http', 'localhost', and '8080' respectively;

json - which defaults to a JSON object with utf8 and allow_blessed turned on but can be replaced with anything with the same interface;

ua - which is a LWP::UserAgent object and can also be replaced.

agent - Replace the name the defaut LWP::UserAgent reports to the db when it crud's

debug - boolean, defaults to false, set to 1 to enable debug messages (show's crud sent to persevere).

auth_type - can be set to basic, json-rpc, or none, basic is default, and throws an error without a username and password. json-rpc auth is not yet implemented.

query_timeout - how long to wait until timing out on a request, defaults to 30.

exist_is_error - return an error if a class we try and create already exists

showwarnings - carp warning messages

testConnection

Returns true if a connection can be made to the server, false otherwise.

req

All requests made to the server that do not have a boolean response return a req hash. All req hashes contain: code - http status code status_line - http status_line (this is what you use to debug why a request failed) success - false for failure, true for success content - content of the request auth - false if authentication failed for the query, true if authentication succeeded

  Successful requests contain:
    data - decoded json data, when assigning this to a variable its type must be declared. most data will be arrays, with the exception of status. 
    Example: 
    my $postreq = $initialclass->createObjects(\@post_data);
    if ($postreq->{success}){
        foreach (@{$postreq->{data}}){
            print "$_\n";
        }
    }else{
        warn "unable to post data";
    }

    range - if applicable returns the range header information for the request.

        using req hashes provides a uniform approach to dealing with error handling for auth, and failed requests.
serverInfo

Returns a req hash, server metadata is contained in {data}, and is typically something that looks like { id => "status", version => "1.0 beta 2" ... }. It throws an warning if it can't connect.

classExists

Returns true if a class of that name exists, false otherwise.

listClassNames

Returns an req hash, with {data} containing all non core class names that the server knows of.

class

Returns a new Persevere::Client::Class object for a class of that name. Note that the Class does not need to exist yet, and will not be created if it doesn't. The create method will create the class, and is documented in Persevere::Client::Class

AUTHOR

Nathanael Anderson, <wirelessdreamer at gm]a[il d[0]t com>

BUGS

Please report any bugs or feature requests to bug-persevere-client at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Persevere-Client. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

    perldoc Persevere::Client

You can also look for information at:

ACKNOWLEDGEMENTS

Thanks to mst in #perl-help on irc.perl.org for looking over the code, and providing feedback

COPYRIGHT & LICENSE

Copyright 2009-2011 Nathanael Anderson.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.