Cookieville::Client - Client that talks with Cookieville server
Cookieville::Client is a client that talks with the Cookieville server.
use Cookieville::Client; my $ua = Cookieville::Client->new(url => 'http://127.0.0.1/'); my $res; $res = $ua->search( 'SomeSource', { col_a => { like => '%42' } }, { limit => 10 }, ); $res = $ua->delete(SomeSource => 123); $res = $ua->put(SomeSource => { col_a => 123 }); $res = $ua->patch(SomeSource => 42 => { col_a => 123 });
Blocking requests will throw an exception on error, while all callbacks receive the error as a string. Example:
use Mojolicious::Lite; get '/artists' => sub { $c->delay( sub { my ($delay) = @_; $c->cookieville_helper->search(Artist => {}, $delay->begin); }, sub { my ($delay, $err, $res) = @_; return $c->reply->exception($err) if $err; return $c->render(json => $res->{data}); }, ); };
$str = $self->id; $self = $self->id($str);
Used to set the "X-Cookieville-Auth-Id" HTTP header. This can be used by the Cookieville::Plugin::Authorize plugin.
Defaults to COOKIEVILLE_AUTH_ID environment variable.
COOKIEVILLE_AUTH_ID
$url_obj = $self->url; $self = $self->url($url_obj);
Holds the base URL to the Cookieville server. Default to "http://127.0.0.1/".
Will make sure "url" in constructor is indeed a Mojo::URL object.
$res = $self->delete($source => $id); $self = $self->delete($source => $id, $cb);
Used to DELETE a single record from $source, identified by id.
$source
id
$res = $self->patch($source => $id => \%data); $self = $self->patch($source => $id => \%data, $cb);
Used to UPDATE a single record from $source, identified by id. %data can be partial or full set of column/values.
%data
$res = $self->put($source => \%data); $self = $self->put($source => \%data, $cb);
Used to INSERT or UPDATE a single row. An UPDATE will be issued if %data contain an unique constraint a matching record in database.
"put" v.s "patch": "patch" will never INSERT a new record, while "put" will make sure a given record exists.
NOTE: %data without any unique constraints will result in INSERT.
$res = $self->search($source => \%query, \%extra); $self = $self->search($source => \%query, \%extra, $cb);
Does a SELECT from the given source with a given %query and %extra parameters. This method is very similar to "search" in DBIx::Class::ResultSet, but with less %extra options:
source
%query
%extra
columns
Only output the given columns. Example:
$extra{columns} = [qw( id name )];
limit
Used to limit the number of rows in the output.
$extra{limit} = 10;
page=:int (optional)
Used for pagination when limit is specified.
$extra{limit} = 2;
order_by
Sort the result by column(s). Examples:
$extra{order_by} = ["name"]; $extra{order_by} = { "-desc" => "name" };
Copyright (C) 2014, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Cookieville, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cookieville
CPAN shell
perl -MCPAN -e shell install Cookieville
For more information on module installation, please visit the detailed CPAN module installation guide.