File Coverage

lib/REST/Cypher.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package REST::Cypher;
2             {
3             $REST::Cypher::DIST = 'REST-Cypher';
4             }
5             $REST::Cypher::VERSION = '0.0.4';
6             # ABSTRACT: Experimental client for using neo4j's REST/Cypher interface
7             # KEYWORDS: neo4j graph graphdb cypher REST
8              
9 2     2   100276 use strict;
  2         5  
  2         53  
10 2     2   10 use warnings;
  2         4  
  2         51  
11              
12 2     2   771 use Moo;
  2         13597  
  2         10  
13 2     2   3686 use MooX::Types::MooseLike::Base qw/Bool/;
  2         13358  
  2         160  
14 2     2   1647 use MooseX::Params::Validate;
  2         1138874  
  2         15  
15              
16 2     2   1938 use REST::Cypher::Agent;
  2         7  
  2         551  
17              
18             has agent => (
19             is => 'rw',
20             lazy => 1,
21             writer => '_set_agent',
22              
23             default => sub {
24             REST::Cypher::Agent->new(
25             base_url => $_[0]->rest_base_url,
26             debug => $_[0]->debug,
27             );
28             },
29             );
30              
31             has server => (
32             is => 'ro',
33             required => 1,
34             default => 'localhost',
35             );
36              
37             has server_port => (
38             is => 'ro',
39             required => 1,
40             default => '7474',
41             );
42              
43             has rest_base_url => (
44             is => 'ro',
45             lazy => 1,
46             default => sub {
47             sprintf(
48             'http://%s:%d',
49             $_[0]->server,
50             $_[0]->server_port,
51             );
52             },
53             );
54              
55             has debug => (
56             is => 'rw',
57             isa => Bool,
58             default => 0,
59             );
60              
61             sub query {
62 2     2 1 235 my ($self, %params) = validated_hash(
63             \@_,
64             query_string => { isa => 'Str' },
65             );
66              
67             my $response = $self->agent->POST(
68             query_string => $params{query_string}
69 2         1068 );
70             }
71              
72             1;
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             REST::Cypher - Experimental client for using neo4j's REST/Cypher interface
81              
82             =head1 VERSION
83              
84             version 0.0.4
85              
86             =head1 SYNOPSIS
87              
88             use Rest::Cypher::Agent;
89             use Data::UUID;
90              
91             my $neo = REST::Cypher::Agent->new({
92             base_url => 'http://example.com:7474',
93             });
94              
95             my ($response, $nodeType);
96              
97             # let's create a GUID for a node
98             my $guid = Data::UUID->new->to_string(Data::UUID->new->create);
99              
100             $nodeType = 'MyNodeType';
101             $response = $neo->POST(
102             query_string => "MERGE (a:${nodeType} {guid: {newGUID}}) RETURN a",
103             query_params => {
104             newGUID => $guid,
105             }
106             );
107              
108             =head1 DESCRIPTION
109              
110             Interact with a neo4j Cypher API.
111              
112             =head1 ATTRIBUTES
113              
114             =head2 agent
115              
116             =head2 server
117              
118             =head2 server_port
119              
120             =head2 rest_base_url
121              
122             =head2 debug
123              
124             =head1 METHODS
125              
126             =head2 query($self, %params)
127              
128             Send a Cypher query to the server,
129              
130             =head1 ACKNOWLEDGMENTS
131              
132             This module was written to scratch an itch after using L<REST::Neo4p>; I liked
133             the L<REST::Neo4p::Query> and wanted to attempt to implement something that
134             felt like it was Cypher driven, and less about specific nodes and indexes.
135              
136             I may be way off the mark, but this module is currently useful for throwing
137             hand-written Cypher at a neo4j server.
138              
139             Over time it may even implement more interesting features.
140              
141             =head1 SEE ALSO
142              
143             =over 4
144              
145             =item *
146              
147             L<REST::Cypher::Agent>
148              
149             =item *
150              
151             L<neo4j|http://neo4j.org>
152              
153             =item *
154              
155             L<REST::Neo4p>
156              
157             =back
158              
159             =head1 AUTHOR
160              
161             Chisel <chisel@chizography.net>
162              
163             =head1 COPYRIGHT AND LICENSE
164              
165             This software is copyright (c) 2015 by Chisel Wright.
166              
167             This is free software; you can redistribute it and/or modify it under
168             the same terms as the Perl 5 programming language system itself.
169              
170             =cut
171              
172             __END__
173             # vim: ts=8 sts=4 et sw=4 sr sta