File Coverage

blib/lib/ArangoDB/Document.pm
Criterion Covered Total %
statement 24 52 46.1
branch 0 4 0.0
condition 0 5 0.0
subroutine 8 15 53.3
pod 4 4 100.0
total 36 80 45.0


line stmt bran cond sub pod time code
1             package ArangoDB::Document;
2 8     8   52 use strict;
  8         17  
  8         317  
3 8     8   49 use warnings;
  8         16  
  8         251  
4 8     8   42 use utf8;
  8         25  
  8         63  
5 8     8   9348 use 5.008001;
  8         33  
  8         2685  
6 8     8   66 use Carp qw(croak);
  8         17  
  8         588  
7 8     8   61 use parent 'ArangoDB::AbstractDocument';
  8         15  
  8         60  
8 8     8   554 use ArangoDB::Constants qw(:api);
  8         21  
  8         1778  
9 8     8   7861 use ArangoDB::Edge;
  8         267  
  8         12393  
10              
11             sub new {
12 0     0 1   my $class = shift;
13 0           my $self = $class->SUPER::new(@_);
14 0           $self->{_api_path} = API_DOCUMENT . '/' . $self;
15 0           return $self;
16             }
17              
18             sub any_edges {
19 0     0 1   my ( $self, $vertex ) = @_;
20 0           return $self->_get_edges('any');
21             }
22              
23             sub in_edges {
24 0     0 1   my ( $self, $vertex ) = @_;
25 0           return $self->_get_edges('in');
26             }
27              
28             sub out_edges {
29 0     0 1   my ( $self, $vertex ) = @_;
30 0           return $self->_get_edges('out');
31             }
32              
33             sub _api_path {
34 0     0     $_[0]->{_api_path};
35             }
36              
37             sub _get_edges {
38 0     0     my ( $self, $direction ) = @_;
39 0           my $vertex = $self->{_document_handle};
40 0           my $api = API_EDGES . '/' . $self->{_collection_id} . '?vertex=' . $vertex . '&direction=' . $direction;
41 0           my $res = eval { $self->{connection}->http_get($api) };
  0            
42 0 0         if ($@) {
43 0           $self->_server_error_handler( $@, "get edges($vertex) that related to" );
44             }
45 0           my $conn = $self->{connection};
46 0           my @edges = map { ArangoDB::Edge->new( $conn, $_ ) } @{ $res->{edges} };
  0            
  0            
47 0           return \@edges;
48             }
49              
50             # Handling server error
51             sub _server_error_handler {
52 0     0     my ( $self, $error, $action ) = @_;
53 0           my $msg = sprintf( 'Failed to %s the document(%s)', $action, $self->{_document_handle} );
54 0 0 0       if ( ref($error) && $error->isa('ArangoDB::ServerException') ) {
55 0   0       $msg .= ':' . ( $error->detail->{errorMessage} || q{} );
56             }
57 0           croak $msg;
58             }
59              
60             1;
61             __END__