Permalink
Browse files

- Add inet_aton option

- Add sample script
  • Loading branch information...
1 parent ec59c76 commit a136537887af10472ab99a2f4c7fa2a18f5a3900 @hideo55 committed Oct 17, 2012
Showing with 142 additions and 127 deletions.
  1. +2 −2 Build.PL
  2. +6 −2 Changes
  3. +19 −10 README
  4. +20 −0 eg/arangodb.pl
  5. +27 −20 lib/ArangoDB.pm
  6. +11 −5 lib/ArangoDB/AbstractDocument.pm
  7. +2 −3 lib/ArangoDB/Collection.pm
  8. +11 −1 lib/ArangoDB/ConnectOptions.pm
  9. +25 −78 lib/ArangoDB/Connection.pm
  10. +2 −2 lib/ArangoDB/Statement.pm
  11. +14 −2 t/01_new.t
  12. +2 −2 t/03_document.t
  13. +1 −0 xt/04_pod_coverage.t
View
@@ -44,12 +44,12 @@ my $build = $class->new(
'Carp' => 0,
'JSON' => '2.53',
'List::MoreUtils' => 0,
- 'Furl::HTTP' => '0.42',
+ 'Furl::HTTP' => '0.42',
'MIME::Base64' => 0,
'Data::Util' => '0.59',
},
recommends => { 'Data::Clone' => 0, },
- no_index => { 'directory' => [ 't', 'xt', 'inc' ] },
+ no_index => { 'directory' => [ 't', 'xt', 'inc', 'eg' ] },
test_files => ( -d '.git' || $ENV{RELEASE_TESTING} ) ? [qw(t/ xt/)] : ['t/'],
create_readme => 1,
add_to_cleanup => ['ArangoDB-*'],
View
@@ -1,6 +1,10 @@
Revision history for Perl extension ArangoDB
-0.03 Wed Oct 17 2:35:00 2012
+0.04 Thu Oct 18 02:00:00 2012
+ - Add inet_aton option
+ - Fixed deps
+
+0.03 Wed Oct 17 02:35:00 2012
- Switch HTTP client Furl to Furl::HTTP
0.02 Tue Oct 16 21:05:00 2012
@@ -16,7 +20,7 @@ Revision history for Perl extension ArangoDB
- Change API(Document/Edge/Index)
- Improved documents
-0.01_02 Fri Oct 12 2:47:00 2012
+0.01_02 Fri Oct 12 02:47:00 2012
- dev release version
0.01_01 Tue Jul 3 22:33:37 2012
View
29 README
@@ -4,11 +4,11 @@ NAME
SYNOPSIS
use ArangoDB;
- my $db = ArangoDB->new({
+ my $db = ArangoDB->new(
host => 'localhost',
port => 8529,
keep_alive => 1,
- });
+ );
# Find or create collection
my $foo = $db->('foo');
@@ -75,30 +75,39 @@ METHODS
proxy
Proxy url for HTTP connection.
- create($name)
- Create new collection. Returns instance of ArangoDB::Collection.
+ inet_aton
+ A callback function to customize name resolution. Takes two
+ arguments: ($hostname, $timeout_in_seconds).
- find($name)
- Get a Collection based on $name. Returns instance of
- ArangoDB::Collection.
-
- If the collection does not exist, returns "undef".
+ See Furl::HTTP.
collection($name)
- Get or create a Collection based on $name.
+ Get or create a collection based on $name. Returns instance of
+ ArangoDB::Collection.
If the Collection $name does not exist, Create it.
There is shorthand method for get collection instance.
my $collection = $db->('collection-name');
+ create($name)
+ Create new collection. Returns instance of ArangoDB::Collection.
+
+ find($name)
+ Get a Collection based on $name. Returns instance of
+ ArangoDB::Collection.
+
+ If the collection does not exist, returns "undef".
+
collections()
Get all collections. Returns ARRAY reference.
query($query)
Get AQL statement handler. Returns instance of ArangoDB::Statement.
+ my $sth = $db->query('FOR u IN users FILTER u.age > @age SORT u.name ASC RETURN u');
+
AUTHOR
Hideaki Ohno <hide.o.j55 {at} gmail.com>
View
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use ArangoDB;
+
+my $db = ArangoDB->new();
+
+my $users = $db->('users');
+
+$users->save({ user => { name => 'John', age => 42 } });
+$users->save({ user => { name => 'Joe', age => 20 } });
+$users->save({ user => { name => 'Alice', age => 10 } });
+
+my $docs = $db->query(
+ 'FOR u IN users FILTER u.user.age >= @age SORT u.user.name RETURN u'
+)->bind( age => 18 )->execute->all;
+
+for my $doc ( @$docs ){
+ print $doc->content->{user}{name}, "\n";
+}
+
View
@@ -9,14 +9,13 @@ use ArangoDB::Collection;
use ArangoDB::Document;
use ArangoDB::Statement;
use ArangoDB::Constants qw(:api);
-
use overload '&{}' => sub {
- my $self = shift;
- return sub { $self->collection( $_[0] ) };
+ my $self = shift;
+ return sub { $self->collection( $_[0] ) };
},
fallback => 1;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
$VERSION = eval $VERSION;
sub new {
@@ -25,6 +24,11 @@ sub new {
return $self;
}
+sub collection {
+ my ( $self, $name ) = @_;
+ return $self->find($name) || $self->create($name);
+}
+
sub create {
my ( $self, $name, $_options ) = @_;
my $params = { ( waitForSync => 0, isSystem => 0 ), %{ $_options || {} } };
@@ -53,11 +57,6 @@ sub find {
return $collection;
}
-sub collection {
- my ( $self, $name ) = @_;
- return $self->find($name) || $self->create($name);
-}
-
sub collections {
my $self = shift;
my $conn = $self->{connection};
@@ -97,11 +96,11 @@ ArangoDB - ArangoDB client for Perl.
use ArangoDB;
- my $db = ArangoDB->new({
+ my $db = ArangoDB->new(
host => 'localhost',
port => 8529,
keep_alive => 1,
- });
+ );
# Find or create collection
my $foo = $db->('foo');
@@ -182,28 +181,34 @@ Password for authentication
Proxy url for HTTP connection.
-=back
-
-=head2 create($name)
-
-Create new collection. Returns instance of L<ArangoDB::Collection>.
+=item inet_aton
-=head2 find($name)
+A callback function to customize name resolution. Takes two arguments: ($hostname, $timeout_in_seconds).
-Get a Collection based on $name. Returns instance of L<ArangoDB::Collection>.
+See L<Furl::HTTP>.
-If the collection does not exist, returns C<undef>.
+=back
=head2 collection($name)
-Get or create a Collection based on $name.
+Get or create a collection based on $name. Returns instance of L<ArangoDB::Collection>.
If the Collection $name does not exist, Create it.
There is shorthand method for get collection instance.
my $collection = $db->('collection-name');
+=head2 create($name)
+
+Create new collection. Returns instance of L<ArangoDB::Collection>.
+
+=head2 find($name)
+
+Get a Collection based on $name. Returns instance of L<ArangoDB::Collection>.
+
+If the collection does not exist, returns C<undef>.
+
=head2 collections()
Get all collections. Returns ARRAY reference.
@@ -212,6 +217,8 @@ Get all collections. Returns ARRAY reference.
Get AQL statement handler. Returns instance of L<ArangoDB::Statement>.
+ my $sth = $db->query('FOR u IN users FILTER u.age > @age SORT u.name ASC RETURN u');
+
=head1 AUTHOR
Hideaki Ohno E<lt>hide.o.j55 {at} gmail.comE<gt>
@@ -57,13 +57,19 @@ sub set {
}
sub fetch {
- my $self = shift;
- my $res = eval { $self->{connection}->http_get( $self->_api_path ) };
+ my ( $self, $no_etag ) = @_;
+ my @header;
+ if ( !$no_etag ) {
+ push @header, 'If-None-Match' => $self->{_rev};
+ }
+ my $res = eval { $self->{connection}->http_get( $self->_api_path, \@header ) };
if ($@) {
$self->_server_error_handler( $@, 'fetch' );
}
- $self->{_rev} = delete $res->{_rev};
- $self->{document} = { map { $_ => $res->{$_} } grep { $_ !~ /^_/ } keys %$res };
+ if ( !defined $res || ref($res) eq 'HASH' ) {
+ $self->{_rev} = delete $res->{_rev};
+ $self->{document} = { map { $_ => $res->{$_} } grep { $_ !~ /^_/ } keys %$res };
+ }
return $self;
}
@@ -73,7 +79,7 @@ sub save {
if ($@) {
$self->_server_error_handler( $@, 'update' );
}
- $self->fetch();
+ $self->fetch(1);
return $self;
}
@@ -408,7 +408,7 @@ sub bulk_import {
unless $body && ref($body) eq 'ARRAY';
my $api = API_IMPORT . '?collection=' . $self->{id};
my $data = join "\n", map { encode_json($_) } ( $header, @$body );
- my $res = eval { $self->{connection}->http_post_raw( $api, $data ); };
+ my $res = eval { $self->{connection}->http_post( $api, $data, 1 ); };
if ($@) {
$self->_server_error_handler( $@, 'Failed to bulk import to the collection(%s)' );
}
@@ -438,7 +438,7 @@ sub bulk_import_self_contained {
unless $documents && ref($documents) eq 'ARRAY';
my $api = API_IMPORT . '?type=documents&collection=' . $self->{id};
my $data = join "\n", map { encode_json($_) } @$documents;
- my $res = eval { $self->{connection}->http_post_raw( $api, $data ); };
+ my $res = eval { $self->{connection}->http_post( $api, $data , 1); };
if ($@) {
$self->_server_error_handler( $@, 'Failed to bulk import to the collection(%s)' );
}
@@ -1155,4 +1155,3 @@ __END__
Hideaki Ohno E<lt>hide.o.j55 {at} gmail.comE<gt>
=cut
-
@@ -22,7 +22,7 @@ sub new {
return $self;
}
-for my $name (qw/host port timeout keep_alive proxy auth_type auth_user auth_passwd/) {
+for my $name (qw/host port timeout keep_alive proxy auth_type auth_user auth_passwd inet_aton/) {
next if __PACKAGE__->can($name);
no strict 'refs';
*{ __PACKAGE__ . '::' . $name } = sub {
@@ -51,6 +51,7 @@ sub _validate {
die "auth_user should be a string" if $options->{auth_user} && !is_string( $options->{auth_user} );
die "auth_passwd should be a string" if $options->{auth_passwd} && !is_string( $options->{auth_passwd} );
+ die "inet_aton should be a CODE reference" if $options->{inet_aton} && !is_code_ref( $options->{inet_aton} );
}
@@ -64,6 +65,7 @@ sub _get_defaults {
auth_type => undef,
keep_alive => 0,
proxy => undef,
+ inet_aton => undef,
};
}
@@ -125,6 +127,12 @@ Password for authentication
Proxy url for HTTP connection.
+=item inet_aton
+
+A callback function to customize name resolution. Takes two arguments: ($hostname, $timeout_in_seconds).
+
+See L<Furl::HTTP>.
+
=back
=head2 host()
@@ -143,6 +151,8 @@ Proxy url for HTTP connection.
=head2 proxy()
+=head2 inet_aton()
+
=head1 AUTHOR
Hideaki Ohno E<lt>hide.o.j55 {at} gmail.comE<gt>
Oops, something went wrong.

0 comments on commit a136537

Please sign in to comment.