| 1 | package FalkorDB::Edge; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | sub new { | ||
| 7 | my ( $class, %args ) = @_; | ||
| 8 | return bless \%args, $class; | ||
| 9 | } | ||
| 10 | |||
| 11 | sub id { shift->{id} } | ||
| 12 | sub type { shift->{type} } | ||
| 13 | sub src_node { shift->{src_node} } | ||
| 14 | sub dest_node { shift->{dest_node} } | ||
| 15 | sub properties { shift->{properties} } | ||
| 16 | |||
| 17 | sub property { | ||
| 18 | my ( $self, $key ) = @_; | ||
| 19 | return $self->{properties}->{$key}; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub new_from_resp { | ||
| 23 | my ( $class, $resp ) = @_; | ||
| 24 | my ( $id, $type, $src_node, $dest_node, $properties ); | ||
| 25 | |||
| 26 | for my $pair (@$resp) { | ||
| 27 | my ( $k, $v ) = @$pair; | ||
| 28 | if ( $k eq 'id' ) { | ||
| 29 | $id = $v; | ||
| 30 | } | ||
| 31 | elsif ( $k eq 'type' ) { | ||
| 32 | $type = $v; | ||
| 33 | } | ||
| 34 | elsif ( $k eq 'src_node' ) { | ||
| 35 | $src_node = $v; | ||
| 36 | } | ||
| 37 | elsif ( $k eq 'dest_node' ) { | ||
| 38 | $dest_node = $v; | ||
| 39 | } | ||
| 40 | elsif ( $k eq 'properties' ) { | ||
| 41 | $properties = FalkorDB::QueryResult::_parse_properties($v); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | return $class->new( | ||
| 46 | id => $id, | ||
| 47 | type => $type, | ||
| 48 | src_node => $src_node, | ||
| 49 | dest_node => $dest_node, | ||
| 50 | properties => $properties || {}, | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 | __END__ |