FalkorDB/Path.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 46 CC 4 SCAR 22.2
CC
4
Cov
0%
new_from_string
20.0
new
2.0
nodes
2.0
CRAP 9.2
1 package FalkorDB::Path;
2  
3 use strict;
4 use warnings;
5  
6 sub new {
7 my ( $class, %args ) = @_;
8 return bless \%args, $class;
9 }
10  
11 sub nodes { shift->{nodes} }
12 sub edges { shift->{edges} }
13 sub elements { shift->{elements} }
14  
15 sub new_from_string {
16 my ( $class, $path_str ) = @_;
17 my @nodes;
18 my @edges;
19 my @elements;
20  
21 if ( $path_str =~ /^\[(.*)\]$/ ) {
22 my $content = $1;
23 while ( $content =~ /(\(\d+\)|\[\d+\])/g ) {
24 my $token = $1;
25 if ( $token =~ /^\((\d+)\)$/ ) {
26 my $node_id = 0 + $1;
27 push @nodes, $node_id;
28 push @elements, { type => 'node', id => $node_id };
29 }
30 elsif ( $token =~ /^\[(\d+)\]$/ ) {
31 my $edge_id = 0 + $1;
32 push @edges, $edge_id;
33 push @elements, { type => 'edge', id => $edge_id };
34 }
35 }
36 }
37  
38 return $class->new(
39 nodes => \@nodes,
40 edges => \@edges,
41 elements => \@elements,
42 );
43 }
44  
45 1;
46 __END__