File Coverage

blib/lib/ArangoDB/Index.pm
Criterion Covered Total %
statement 27 45 60.0
branch 0 4 0.0
condition 0 5 0.0
subroutine 9 13 69.2
pod 0 2 0.0
total 36 69 52.1


line stmt bran cond sub pod time code
1             package ArangoDB::Index;
2 8     8   5136 use strict;
  8         16  
  8         277  
3 8     8   42 use warnings;
  8         16  
  8         196  
4 8     8   39 use utf8;
  8         15  
  8         41  
5 8     8   255 use 5.008001;
  8         26  
  8         422  
6 8     8   59 use Carp qw(croak);
  8         19  
  8         538  
7 8     8   51 use Scalar::Util qw(weaken);
  8         17  
  8         848  
8 8     8   55 use ArangoDB::Constants qw(:api);
  8         18  
  8         1695  
9 8     8   50 use Class::Accessor::Lite ( ro => [qw/id collection_id type/] );
  8         19  
  8         121  
10              
11             use overload
12 0     0     q{""} => sub { $_[0]->id },
13 8     8   1313 fallback => 1;
  8         15  
  8         233  
14              
15             sub new {
16 0     0 0   my ( $class, $conn, $params ) = @_;
17 0           my $self = bless { %$params, connection => $conn, }, $class;
18 0           weaken( $self->{connection} );
19 0           $self->{collection_id} = ( split '/', $self->{id} )[0];
20 0           $self->{_api_path} = API_INDEX . '/' . $self->{id};
21 0           return $self;
22             }
23              
24             sub drop {
25 0     0 0   my $self = shift;
26 0           my $res = eval { $self->{connection}->http_delete( $self->{_api_path} ) };
  0            
27 0 0         if ($@) {
28 0           $self->_server_error_handler( $@, 'drop' );
29             }
30 0           return;
31             }
32              
33             # Handling server error
34             sub _server_error_handler {
35 0     0     my ( $self, $error, $action ) = @_;
36 0           my $msg = sprintf( 'Failed to %s the index(%s)', $action, $self->{id} );
37 0 0 0       if ( ref($error) && $error->isa('ArangoDB::ServerException') ) {
38 0   0       $msg .= ':' . ( $error->detail->{errorMessage} || q{} );
39             }
40 0           croak $msg;
41             }
42              
43             1;
44             __END__