| 1 | package Graph::Feather; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use DBD::SQLite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION_INT = | |||||||||||||||||||||||||||
| 11 | 1_000_000 * version->parse($VERSION)->numify; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Archive::Zip crc32 of 'Graph::Feather' | ||||||||||||||||||||||||||||
| 14 | 4 | our $APPLICATION_ID = -801604570; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1002 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 1002 | my ($class, %options) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1002 | my $self = bless { | |||||||||||||||||||||||||||
| 20 | }, $class; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1002 | my $db_file = ':memory:'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1002 | $self->{dbh} = DBI | |||||||||||||||||||||||||||
| 25 | ->connect("dbi:SQLite:dbname=$db_file", "", ""); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1002 | local $self->{dbh}->{sqlite_allow_multiple_statements} = 1; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | ################################################################### | ||||||||||||||||||||||||||||
| 30 | # Deploy DB schema | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1002 | $self->{dbh}->do(sprintf q{ | |||||||||||||||||||||||||||
| 33 | PRAGMA application_id = %i; | ||||||||||||||||||||||||||||
| 34 | PRAGMA user_version = %u; | ||||||||||||||||||||||||||||
| 35 | }, $APPLICATION_ID, $VERSION_INT); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1002 | $self->{dbh}->do(q{ | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 40 | -- Pragmata | ||||||||||||||||||||||||||||
| 41 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | PRAGMA foreign_keys = ON; | ||||||||||||||||||||||||||||
| 44 | PRAGMA synchronous = OFF; | ||||||||||||||||||||||||||||
| 45 | PRAGMA journal_mode = OFF; | ||||||||||||||||||||||||||||
| 46 | PRAGMA locking_mode = EXCLUSIVE; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 49 | -- Graph | ||||||||||||||||||||||||||||
| 50 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | CREATE TABLE Graph_Attribute( | ||||||||||||||||||||||||||||
| 53 | attribute_name UNIQUE NOT NULL, | ||||||||||||||||||||||||||||
| 54 | attribute_value | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 58 | -- Vertices | ||||||||||||||||||||||||||||
| 59 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | CREATE TABLE Vertex( | ||||||||||||||||||||||||||||
| 62 | vertex_name UNIQUE NOT NULL | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | CREATE TABLE Vertex_Attribute( | ||||||||||||||||||||||||||||
| 66 | vertex NOT NULL, | ||||||||||||||||||||||||||||
| 67 | attribute_name NOT NULL, | ||||||||||||||||||||||||||||
| 68 | attribute_value, | ||||||||||||||||||||||||||||
| 69 | UNIQUE(vertex, attribute_name), | ||||||||||||||||||||||||||||
| 70 | FOREIGN KEY (vertex) | ||||||||||||||||||||||||||||
| 71 | REFERENCES Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 72 | ON DELETE CASCADE | ||||||||||||||||||||||||||||
| 73 | ON UPDATE CASCADE | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 77 | -- Edges | ||||||||||||||||||||||||||||
| 78 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | CREATE TABLE Edge( | ||||||||||||||||||||||||||||
| 81 | src NOT NULL, | ||||||||||||||||||||||||||||
| 82 | dst NOT NULL, | ||||||||||||||||||||||||||||
| 83 | UNIQUE(src, dst), | ||||||||||||||||||||||||||||
| 84 | FOREIGN KEY (src) | ||||||||||||||||||||||||||||
| 85 | REFERENCES Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 86 | ON DELETE CASCADE | ||||||||||||||||||||||||||||
| 87 | ON UPDATE CASCADE | ||||||||||||||||||||||||||||
| 88 | FOREIGN KEY (dst) | ||||||||||||||||||||||||||||
| 89 | REFERENCES Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 90 | ON DELETE CASCADE | ||||||||||||||||||||||||||||
| 91 | ON UPDATE CASCADE | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | -- Can use covering index instead | ||||||||||||||||||||||||||||
| 95 | -- CREATE INDEX idx_Edge_src | ||||||||||||||||||||||||||||
| 96 | -- ON Edge (src); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | CREATE INDEX idx_Edge_dst | ||||||||||||||||||||||||||||
| 99 | ON Edge (dst); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | CREATE TABLE Edge_Attribute( | ||||||||||||||||||||||||||||
| 102 | src NOT NULL, | ||||||||||||||||||||||||||||
| 103 | dst NOT NULL, | ||||||||||||||||||||||||||||
| 104 | attribute_name NOT NULL, | ||||||||||||||||||||||||||||
| 105 | attribute_value, | ||||||||||||||||||||||||||||
| 106 | UNIQUE(src, dst, attribute_name), | ||||||||||||||||||||||||||||
| 107 | FOREIGN KEY (src, dst) | ||||||||||||||||||||||||||||
| 108 | REFERENCES Edge(src, dst) | ||||||||||||||||||||||||||||
| 109 | ON DELETE CASCADE | ||||||||||||||||||||||||||||
| 110 | ON UPDATE CASCADE | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 114 | -- Triggers that add vertices and edges when needed elsewhere | ||||||||||||||||||||||||||||
| 115 | ----------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | CREATE TRIGGER trigger_Edge_insert | ||||||||||||||||||||||||||||
| 118 | BEFORE INSERT ON Edge | ||||||||||||||||||||||||||||
| 119 | BEGIN | ||||||||||||||||||||||||||||
| 120 | INSERT OR IGNORE | ||||||||||||||||||||||||||||
| 121 | INTO Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 122 | VALUES(NEW.src); | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | INSERT OR IGNORE | ||||||||||||||||||||||||||||
| 125 | INTO Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 126 | VALUES(NEW.dst); | ||||||||||||||||||||||||||||
| 127 | END; | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | CREATE TRIGGER trigger_Vertex_Attribute_insert | ||||||||||||||||||||||||||||
| 130 | BEFORE INSERT ON Vertex_Attribute | ||||||||||||||||||||||||||||
| 131 | BEGIN | ||||||||||||||||||||||||||||
| 132 | INSERT OR IGNORE | ||||||||||||||||||||||||||||
| 133 | INTO Vertex(vertex_name) | ||||||||||||||||||||||||||||
| 134 | VALUES(NEW.vertex); | ||||||||||||||||||||||||||||
| 135 | END; | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | CREATE TRIGGER trigger_Edge_Attribute_insert | ||||||||||||||||||||||||||||
| 138 | BEFORE INSERT ON Edge_Attribute | ||||||||||||||||||||||||||||
| 139 | BEGIN | ||||||||||||||||||||||||||||
| 140 | INSERT OR IGNORE | ||||||||||||||||||||||||||||
| 141 | INTO Edge(src, dst) | ||||||||||||||||||||||||||||
| 142 | VALUES(NEW.src, NEW.dst); | ||||||||||||||||||||||||||||
| 143 | END; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | }); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | ################################################################### | ||||||||||||||||||||||||||||
| 148 | # Register hook to synchronise attribute Perl objects | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 57018 | ▶ | $self->{dbh}->sqlite_update_hook(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 151 | 57018 | ▶ | return unless $_[0] == 9; # DBD::SQLite::DELETE | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 9942 | delete $self->{ $_[2] }{ $_[3] }; | |||||||||||||||||||||||||||
| 153 | 1002 | }); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | ################################################################### | ||||||||||||||||||||||||||||
| 156 | # Process options | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 1001 | $self->add_vertices(@{ $options{vertices} }) | |||||||||||||||||||||||||||
| 159 | 1002 | ▶ | if exists $options{vertices}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1001 | $self->add_edges(@{ $options{edges} }) | |||||||||||||||||||||||||||
| 162 | 1002 | ▶ | if exists $options{edges}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1002 | return $self; | |||||||||||||||||||||||||||
| 165 | }; | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | ##################################################################### | ||||||||||||||||||||||||||||
| 168 | # DB helpers | ||||||||||||||||||||||||||||
| 169 | ##################################################################### | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 32437 | ▶ | sub _prepare { | ||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||
| 172 | 32437 | my ($self, $statement, $attr, @other) = @_; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # TODO(bh): As of 2018-02 effect/purpose of %attr seems | ||||||||||||||||||||||||||||
| 175 | # undefined in DBI documentation. So we fail on them here. | ||||||||||||||||||||||||||||
| 176 | 32437 | ▶ | if ($attr or @other) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$attr or @other
MC/DC0%0/2
$attr or @other
$attr
@other
Truth table33%1/3
A or B
A= $attrB= @other
| |||||||||||||||||||||||||||||
| 177 | ... | ||||||||||||||||||||||||||||
| 178 | 0 | } | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 32437 | ▶ | $self->{cache}{$statement} //= $self->{dbh}->prepare($statement); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"cache"}{$statement} //= $self->{"dbh"}->prepare($statement)
MC/DC0%0/2
$self->{"cache"}{$statement} //= $self->{"dbh"}->prepare($statement)
$self->{"cache"}{$statement}
$self->{"dbh"}->prepare($statement)
Truth table66%2/3
A //= B
A= $self->{"cache"}{$statement}B= $self->{"dbh"}->prepare($statement)
| |||||||||||||||||||||||||||||
| 181 | 32437 | return $self->{cache}{$statement}; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | ##################################################################### | ||||||||||||||||||||||||||||
| 185 | # Basics | ||||||||||||||||||||||||||||
| 186 | ##################################################################### | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1019 | ▶ | sub add_vertex { | ||||||||||||||||||||||||||
|
Subroutine
add_vertex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 1019 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 190 | 1019 | add_vertices($self, $v); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1088 | ▶ | sub add_edge { | ||||||||||||||||||||||||||
|
Subroutine
add_edge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | 1088 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 195 | 1088 | add_edges($self, [$src, $dst]); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 1079 | ▶ | sub has_vertex { | ||||||||||||||||||||||||||
|
Subroutine
has_vertex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 1079 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 1079 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 202 | SELECT 1 FROM Vertex WHERE vertex_name = ? | ||||||||||||||||||||||||||||
| 203 | }); | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 1079 | my ($result) = $self->{dbh}->selectrow_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1079 | return !!$result; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 461 | ▶ | sub has_edge { | ||||||||||||||||||||||||||
|
Subroutine
has_edge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 461 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 461 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 214 | SELECT 1 FROM Edge WHERE src = ? AND dst = ? | ||||||||||||||||||||||||||||
| 215 | }); | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 461 | my ($result) = $self->{dbh}->selectrow_array($sth, {}, $src, $dst); | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 461 | return !!$result; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 523 | ▶ | sub delete_vertex { | ||||||||||||||||||||||||||
|
Subroutine
delete_vertex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | 523 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 523 | delete_vertices($self, $v); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 1023 | ▶ | sub delete_vertices { | ||||||||||||||||||||||||||
|
Subroutine
delete_vertices: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 1023 | my ($self, @vertices) = @_; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # delete_vertex_attributes($self, $_) for @vertices; | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 1023 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 234 | DELETE FROM Vertex WHERE vertex_name = ? | ||||||||||||||||||||||||||||
| 235 | }); | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 1023 | $self->{dbh}->begin_work(); | |||||||||||||||||||||||||||
| 238 | 1023 | $sth->execute($_) for @vertices; | |||||||||||||||||||||||||||
| 239 | 1023 | $sth->finish(); | |||||||||||||||||||||||||||
| 240 | 1023 | $self->{dbh}->commit(); | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 521 | ▶ | sub delete_edge { | ||||||||||||||||||||||||||
|
Subroutine
delete_edge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | 521 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 245 | 521 | feather_delete_edges($self, [$src, $dst]); | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 270 | ▶ | sub delete_edges { | ||||||||||||||||||||||||||
|
Subroutine
delete_edges: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 249 | 270 | my ($self, @vertices) = @_; | |||||||||||||||||||||||||||
| 250 | 270 | my @edges; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 270 | ▶ | while (@vertices) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 800 | my ($src, $dst) = splice @vertices, 0, 2; | |||||||||||||||||||||||||||
| 254 | 800 | ▶ | warn 'delete_edges takes vertex list, not list of vertex pairs' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | if ref $src; | ||||||||||||||||||||||||||||
| 256 | 800 | push @edges, [ $src, $dst ]; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 270 | $self->feather_delete_edges(@edges); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 791 | ▶ | sub feather_delete_edges { | ||||||||||||||||||||||||||
|
Subroutine
feather_delete_edges: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 263 | 791 | my ($self, @edges) = @_; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 791 | delete_edge_attributes($self, @$_) for @edges; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 791 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 268 | DELETE FROM Edge WHERE src = ? AND dst = ? | ||||||||||||||||||||||||||||
| 269 | }); | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 791 | $self->{dbh}->begin_work(); | |||||||||||||||||||||||||||
| 272 | 791 | $sth->execute(@$_) for @edges; | |||||||||||||||||||||||||||
| 273 | 791 | $sth->finish(); | |||||||||||||||||||||||||||
| 274 | 791 | $self->{dbh}->commit(); | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | ##################################################################### | ||||||||||||||||||||||||||||
| 278 | # Mutators | ||||||||||||||||||||||||||||
| 279 | ##################################################################### | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 2529 | ▶ | sub add_vertices { | ||||||||||||||||||||||||||
|
Subroutine
add_vertices: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 282 | 2529 | my ($self, @vertices) = @_; | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 2529 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 285 | INSERT OR IGNORE INTO Vertex(vertex_name) VALUES (?) | ||||||||||||||||||||||||||||
| 286 | }); | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 2529 | $self->{dbh}->begin_work(); | |||||||||||||||||||||||||||
| 289 | 2529 | $sth->execute($_) for @vertices; | |||||||||||||||||||||||||||
| 290 | 2529 | $sth->finish(); | |||||||||||||||||||||||||||
| 291 | 2529 | $self->{dbh}->commit; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 2622 | ▶ | sub add_edges { | ||||||||||||||||||||||||||
|
Subroutine
add_edges: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 2622 | my ($self, @edges) = @_; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 2622 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 298 | INSERT OR IGNORE INTO Edge(src, dst) VALUES (?, ?) | ||||||||||||||||||||||||||||
| 299 | }); | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 2622 | $self->{dbh}->begin_work(); | |||||||||||||||||||||||||||
| 302 | 2622 | $sth->execute(@$_) for @edges; | |||||||||||||||||||||||||||
| 303 | 2622 | $sth->finish(); | |||||||||||||||||||||||||||
| 304 | 2622 | $self->{dbh}->commit(); | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | ##################################################################### | ||||||||||||||||||||||||||||
| 308 | # Accessors | ||||||||||||||||||||||||||||
| 309 | ##################################################################### | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 507 | ▶ | sub vertices { | ||||||||||||||||||||||||||
|
Subroutine
vertices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 507 | my ($self) = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 507 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 315 | SELECT vertex_name FROM Vertex | ||||||||||||||||||||||||||||
| 316 | }); | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 507 | return map { @$_ } $self->{dbh}->selectall_array($sth); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 500 | ▶ | sub edges { | ||||||||||||||||||||||||||
|
Subroutine
edges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 322 | 500 | my ($self) = @_; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 500 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 325 | SELECT src, dst FROM Edge | ||||||||||||||||||||||||||||
| 326 | }); | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 500 | return $self->{dbh}->selectall_array($sth); | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 504 | ▶ | sub successors { | ||||||||||||||||||||||||||
|
Subroutine
successors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 332 | 504 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 504 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 335 | SELECT dst FROM Edge WHERE src = ? | ||||||||||||||||||||||||||||
| 336 | }); | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 504 | return map { @$_ } $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 493 | ▶ | sub all_successors { | ||||||||||||||||||||||||||
|
Subroutine
all_successors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 342 | 493 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 493 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 345 | WITH RECURSIVE all_successors(v) AS ( | ||||||||||||||||||||||||||||
| 346 | SELECT dst FROM Edge WHERE src = ? | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | UNION | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | SELECT dst | ||||||||||||||||||||||||||||
| 351 | FROM Edge | ||||||||||||||||||||||||||||
| 352 | INNER JOIN all_successors | ||||||||||||||||||||||||||||
| 353 | ON (Edge.src = all_successors.v) | ||||||||||||||||||||||||||||
| 354 | ) | ||||||||||||||||||||||||||||
| 355 | SELECT v FROM all_successors | ||||||||||||||||||||||||||||
| 356 | }); | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 493 | return map { @$_ } $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 495 | ▶ | sub successorless_vertices { | ||||||||||||||||||||||||||
|
Subroutine
successorless_vertices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 362 | 495 | my ($self) = @_; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 495 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 365 | SELECT vertex_name | ||||||||||||||||||||||||||||
| 366 | FROM Vertex | ||||||||||||||||||||||||||||
| 367 | LEFT JOIN Edge | ||||||||||||||||||||||||||||
| 368 | ON (Vertex.vertex_name = Edge.src) | ||||||||||||||||||||||||||||
| 369 | WHERE Edge.dst IS NULL | ||||||||||||||||||||||||||||
| 370 | }); | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 495 | return map { @$_ } $self->{dbh}->selectall_array($sth); | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 515 | ▶ | sub predecessors { | ||||||||||||||||||||||||||
|
Subroutine
predecessors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 376 | 515 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 515 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 379 | SELECT src FROM Edge WHERE dst = ? | ||||||||||||||||||||||||||||
| 380 | }); | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 515 | return map { @$_ } $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 529 | ▶ | sub all_predecessors { | ||||||||||||||||||||||||||
|
Subroutine
all_predecessors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 386 | 529 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 529 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 389 | WITH RECURSIVE all_predecessors(v) AS ( | ||||||||||||||||||||||||||||
| 390 | SELECT src FROM Edge WHERE dst = ? | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | UNION | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | SELECT src | ||||||||||||||||||||||||||||
| 395 | FROM Edge | ||||||||||||||||||||||||||||
| 396 | INNER JOIN all_predecessors | ||||||||||||||||||||||||||||
| 397 | ON (Edge.dst = all_predecessors.v) | ||||||||||||||||||||||||||||
| 398 | ) | ||||||||||||||||||||||||||||
| 399 | SELECT v FROM all_predecessors | ||||||||||||||||||||||||||||
| 400 | }); | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 529 | return map { @$_ } $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 498 | ▶ | sub predecessorless_vertices { | ||||||||||||||||||||||||||
|
Subroutine
predecessorless_vertices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 406 | 498 | my ($self) = @_; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 498 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 409 | SELECT vertex_name | ||||||||||||||||||||||||||||
| 410 | FROM Vertex | ||||||||||||||||||||||||||||
| 411 | LEFT JOIN Edge | ||||||||||||||||||||||||||||
| 412 | ON (Vertex.vertex_name = Edge.dst) | ||||||||||||||||||||||||||||
| 413 | WHERE Edge.src IS NULL | ||||||||||||||||||||||||||||
| 414 | }); | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 498 | return map { @$_ } $self->{dbh}->selectall_array($sth); | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | ##################################################################### | ||||||||||||||||||||||||||||
| 420 | # Degree | ||||||||||||||||||||||||||||
| 421 | ##################################################################### | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 506 | ▶ | sub edges_at { | ||||||||||||||||||||||||||
|
Subroutine
edges_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | 506 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 506 | return $self->{dbh}->selectall_array(q{ | |||||||||||||||||||||||||||
| 427 | SELECT src, dst | ||||||||||||||||||||||||||||
| 428 | FROM Edge | ||||||||||||||||||||||||||||
| 429 | WHERE (?) IN (src, dst) | ||||||||||||||||||||||||||||
| 430 | }, {}, $v); | ||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 528 | ▶ | sub edges_to { | ||||||||||||||||||||||||||
|
Subroutine
edges_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 434 | 528 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 528 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 437 | SELECT src, dst | ||||||||||||||||||||||||||||
| 438 | FROM Edge | ||||||||||||||||||||||||||||
| 439 | WHERE dst = ? | ||||||||||||||||||||||||||||
| 440 | }); | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 528 | return $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 475 | ▶ | sub edges_from { | ||||||||||||||||||||||||||
|
Subroutine
edges_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 446 | 475 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 475 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 449 | SELECT src, dst | ||||||||||||||||||||||||||||
| 450 | FROM Edge | ||||||||||||||||||||||||||||
| 451 | WHERE src = ? | ||||||||||||||||||||||||||||
| 452 | }); | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 475 | return $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | ##################################################################### | ||||||||||||||||||||||||||||
| 458 | # Attributes | ||||||||||||||||||||||||||||
| 459 | ##################################################################### | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | ##################################################################### | ||||||||||||||||||||||||||||
| 462 | # Vertex Attributes | ||||||||||||||||||||||||||||
| 463 | ##################################################################### | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 1130 | ▶ | sub set_vertex_attribute { | ||||||||||||||||||||||||||
|
Subroutine
set_vertex_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 466 | 1130 | my ($self, $v, $name, $value) = @_; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 1130 | delete_vertex_attribute($self, $v, $name); | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 1130 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 471 | INSERT INTO Vertex_Attribute( | ||||||||||||||||||||||||||||
| 472 | vertex, attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 473 | ) | ||||||||||||||||||||||||||||
| 474 | VALUES (?, ?, ?) | ||||||||||||||||||||||||||||
| 475 | }); | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 1130 | $sth->execute($v, $name, $value); | |||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 1130 | my $id = $self->{dbh}->sqlite_last_insert_rowid(); | |||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 1130 | $sth->finish(); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 1130 | $self->{Vertex_Attribute}{ $id } = $value; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 1011 | ▶ | sub _get_vertex_attribute_value_id { | ||||||||||||||||||||||||||
|
Subroutine
_get_vertex_attribute_value_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 487 | 1011 | my ($self, $v, $name) = @_; | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 1011 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 490 | SELECT rowid | ||||||||||||||||||||||||||||
| 491 | FROM Vertex_Attribute | ||||||||||||||||||||||||||||
| 492 | WHERE vertex = ? | ||||||||||||||||||||||||||||
| 493 | AND attribute_name = ? | ||||||||||||||||||||||||||||
| 494 | }); | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 1011 | my ($rowid) = $self->{dbh}->selectrow_array($sth, {}, $v, $name); | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 1011 | return $rowid; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 501 | ▶ | sub get_vertex_attribute { | ||||||||||||||||||||||||||
|
Subroutine
get_vertex_attribute: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 502 | 501 | my ($self, $v, $name) = @_; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 501 | my $rowid = _get_vertex_attribute_value_id($self, $v, $name); | |||||||||||||||||||||||||||
| 505 | 501 | ▶ | return unless defined $rowid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | 8 | return $self->{Vertex_Attribute}{ $rowid }; | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 479 | ▶ | sub set_vertex_attributes { | ||||||||||||||||||||||||||
|
Subroutine
set_vertex_attributes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 510 | 479 | my ($self, $v, $attr) = @_; | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 479 | $self->delete_vertex_attributes($v); | |||||||||||||||||||||||||||
| 513 | 479 | $self->add_vertex($v); | |||||||||||||||||||||||||||
| 514 | $self->set_vertex_attribute($v, $_, $attr->{$_}) | ||||||||||||||||||||||||||||
| 515 | 479 | for keys %$attr; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 529 | ▶ | sub get_vertex_attributes { | ||||||||||||||||||||||||||
|
Subroutine
get_vertex_attributes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 519 | 529 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 529 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 522 | SELECT | ||||||||||||||||||||||||||||
| 523 | rowid, | ||||||||||||||||||||||||||||
| 524 | attribute_name | ||||||||||||||||||||||||||||
| 525 | FROM Vertex_Attribute | ||||||||||||||||||||||||||||
| 526 | WHERE vertex = ? | ||||||||||||||||||||||||||||
| 527 | }); | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 529 | my @result; | |||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 529 | for ($self->{dbh}->selectall_array($sth, {}, $v)) { | |||||||||||||||||||||||||||
| 532 | push @result, | ||||||||||||||||||||||||||||
| 533 | $_->[1], | ||||||||||||||||||||||||||||
| 534 | 28 | $self->{Vertex_Attribute}{ $_->[0] }; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 529 | ▶ | return undef unless $self->has_vertex($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | 336 | return { @result }; | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 510 | ▶ | sub has_vertex_attribute { | ||||||||||||||||||||||||||
|
Subroutine
has_vertex_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 542 | 510 | my ($self, $v, $name) = @_; | |||||||||||||||||||||||||||
| 543 | 510 | my $rowid = _get_vertex_attribute_value_id($self, $v, $name); | |||||||||||||||||||||||||||
| 544 | 510 | return defined $rowid; | |||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | 1645 | ▶ | sub delete_vertex_attribute { | ||||||||||||||||||||||||||
|
Subroutine
delete_vertex_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 548 | 1645 | my ($self, $v, $name) = @_; | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 1645 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 551 | DELETE | ||||||||||||||||||||||||||||
| 552 | FROM Vertex_Attribute | ||||||||||||||||||||||||||||
| 553 | WHERE vertex = ? | ||||||||||||||||||||||||||||
| 554 | AND attribute_name = ? | ||||||||||||||||||||||||||||
| 555 | }); | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 1645 | $sth->execute($v, $name); | |||||||||||||||||||||||||||
| 558 | 1645 | $sth->finish(); | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 525 | ▶ | sub get_vertex_attribute_names { | ||||||||||||||||||||||||||
|
Subroutine
get_vertex_attribute_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 562 | 525 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 525 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 565 | SELECT attribute_name | ||||||||||||||||||||||||||||
| 566 | FROM Vertex_Attribute | ||||||||||||||||||||||||||||
| 567 | WHERE vertex = ? | ||||||||||||||||||||||||||||
| 568 | }); | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 525 | return map { @$_ } $self->{dbh}->selectall_array($sth, {}, $v); | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 959 | ▶ | sub delete_vertex_attributes { | ||||||||||||||||||||||||||
|
Subroutine
delete_vertex_attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 574 | 959 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | 959 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 577 | DELETE | ||||||||||||||||||||||||||||
| 578 | FROM Vertex_Attribute | ||||||||||||||||||||||||||||
| 579 | WHERE vertex = ? | ||||||||||||||||||||||||||||
| 580 | }); | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 959 | $sth->execute($v); | |||||||||||||||||||||||||||
| 583 | 959 | $sth->finish(); | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | ##################################################################### | ||||||||||||||||||||||||||||
| 587 | # Edge Attributes | ||||||||||||||||||||||||||||
| 588 | ##################################################################### | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | 1192 | ▶ | sub set_edge_attribute { | ||||||||||||||||||||||||||
|
Subroutine
set_edge_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 591 | 1192 | my ($self, $src, $dst, $name, $value) = @_; | |||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 1192 | delete_edge_attribute($self, $src, $dst, $name); | |||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 1192 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 596 | INSERT INTO Edge_Attribute( | ||||||||||||||||||||||||||||
| 597 | src, dst, attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 598 | ) | ||||||||||||||||||||||||||||
| 599 | VALUES (?, ?, ?, ?) | ||||||||||||||||||||||||||||
| 600 | }); | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | 1192 | $sth->execute($src, $dst, $name, $value); | |||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 1192 | my $id = $self->{dbh}->sqlite_last_insert_rowid(); | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 1192 | $sth->finish(); | |||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | 1192 | $self->{Edge_Attribute}{ $id } = $value; | |||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | 994 | ▶ | sub _get_edge_attribute_value_id { | ||||||||||||||||||||||||||
|
Subroutine
_get_edge_attribute_value_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 612 | 994 | my ($self, $src, $dst, $name) = @_; | |||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 994 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 615 | SELECT rowid | ||||||||||||||||||||||||||||
| 616 | FROM Edge_Attribute | ||||||||||||||||||||||||||||
| 617 | WHERE src = ? | ||||||||||||||||||||||||||||
| 618 | AND dst = ? | ||||||||||||||||||||||||||||
| 619 | AND attribute_name = ? | ||||||||||||||||||||||||||||
| 620 | }); | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 994 | my ($rowid) = $self->{dbh}->selectrow_array($sth, | |||||||||||||||||||||||||||
| 623 | {}, $src, $dst, $name); | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | 994 | return $rowid; | |||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 492 | ▶ | sub get_edge_attribute { | ||||||||||||||||||||||||||
|
Subroutine
get_edge_attribute: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 629 | 492 | my ($self, $src, $dst, $name) = @_; | |||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | 492 | my $rowid = _get_edge_attribute_value_id($self, $src, $dst, $name); | |||||||||||||||||||||||||||
| 632 | 492 | ▶ | return unless defined $rowid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 633 | 2 | return $self->{Edge_Attribute}{ $rowid }; | |||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | 522 | ▶ | sub get_edge_attributes { | ||||||||||||||||||||||||||
|
Subroutine
get_edge_attributes: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 637 | 522 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | 522 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 640 | SELECT | ||||||||||||||||||||||||||||
| 641 | rowid, | ||||||||||||||||||||||||||||
| 642 | attribute_name | ||||||||||||||||||||||||||||
| 643 | FROM Edge_Attribute | ||||||||||||||||||||||||||||
| 644 | WHERE src = ? | ||||||||||||||||||||||||||||
| 645 | AND dst = ? | ||||||||||||||||||||||||||||
| 646 | }); | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 522 | my @result; | |||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | 522 | for ($self->{dbh}->selectall_array($sth, {}, $src, $dst)) { | |||||||||||||||||||||||||||
| 651 | push @result, | ||||||||||||||||||||||||||||
| 652 | $_->[1], | ||||||||||||||||||||||||||||
| 653 | 0 | $self->{Edge_Attribute}{ $_->[0] }; | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 522 | return { @result }; | |||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | 502 | ▶ | sub has_edge_attribute { | ||||||||||||||||||||||||||
|
Subroutine
has_edge_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 660 | 502 | my ($self, $src, $dst, $name) = @_; | |||||||||||||||||||||||||||
| 661 | 502 | my $rowid = _get_edge_attribute_value_id($self, $src, $dst, $name); | |||||||||||||||||||||||||||
| 662 | 502 | return defined $rowid; | |||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 547 | ▶ | sub set_edge_attributes { | ||||||||||||||||||||||||||
|
Subroutine
set_edge_attributes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 666 | 547 | my ($self, $src, $dst, $attr) = @_; | |||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | 547 | $self->delete_edge_attributes($src, $dst); | |||||||||||||||||||||||||||
| 669 | 547 | $self->add_edge($src, $dst); | |||||||||||||||||||||||||||
| 670 | $self->set_edge_attribute($src, $dst, $_, $attr->{$_}) | ||||||||||||||||||||||||||||
| 671 | 547 | for keys %$attr; | |||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | 1723 | ▶ | sub delete_edge_attribute { | ||||||||||||||||||||||||||
|
Subroutine
delete_edge_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 675 | 1723 | my ($self, $src, $dst, $name) = @_; | |||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | 1723 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 678 | DELETE | ||||||||||||||||||||||||||||
| 679 | FROM Edge_Attribute | ||||||||||||||||||||||||||||
| 680 | WHERE src = ? | ||||||||||||||||||||||||||||
| 681 | AND dst = ? | ||||||||||||||||||||||||||||
| 682 | AND attribute_name = ? | ||||||||||||||||||||||||||||
| 683 | }); | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 1723 | $sth->execute($src, $dst, $name); | |||||||||||||||||||||||||||
| 686 | 1723 | $sth->finish(); | |||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | 540 | ▶ | sub get_edge_attribute_names { | ||||||||||||||||||||||||||
|
Subroutine
get_edge_attribute_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 690 | 540 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | 540 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 693 | SELECT attribute_name | ||||||||||||||||||||||||||||
| 694 | FROM Edge_Attribute | ||||||||||||||||||||||||||||
| 695 | WHERE src = ? | ||||||||||||||||||||||||||||
| 696 | AND dst = ? | ||||||||||||||||||||||||||||
| 697 | }); | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | 540 | return map { @$_ } $self->{dbh}->selectall_array($sth, | |||||||||||||||||||||||||||
| 700 | {}, $src, $dst); | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | 2373 | ▶ | sub delete_edge_attributes { | ||||||||||||||||||||||||||
|
Subroutine
delete_edge_attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 704 | 2373 | my ($self, $src, $dst) = @_; | |||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | 2373 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 707 | DELETE | ||||||||||||||||||||||||||||
| 708 | FROM Edge_Attribute | ||||||||||||||||||||||||||||
| 709 | WHERE src = ? | ||||||||||||||||||||||||||||
| 710 | AND dst = ? | ||||||||||||||||||||||||||||
| 711 | }); | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | 2373 | $sth->execute($src, $dst); | |||||||||||||||||||||||||||
| 714 | 2373 | $sth->finish(); | |||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | ##################################################################### | ||||||||||||||||||||||||||||
| 718 | # Graph Attributes | ||||||||||||||||||||||||||||
| 719 | ##################################################################### | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 1140 | ▶ | sub set_graph_attribute { | ||||||||||||||||||||||||||
|
Subroutine
set_graph_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 722 | 1140 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | 1140 | delete_graph_attribute($self, $name); | |||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | 1140 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 727 | INSERT INTO Graph_Attribute( | ||||||||||||||||||||||||||||
| 728 | attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 729 | ) | ||||||||||||||||||||||||||||
| 730 | VALUES (?, ?) | ||||||||||||||||||||||||||||
| 731 | }); | ||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | 1140 | $sth->execute($name, $value); | |||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | 1140 | my $id = $self->{dbh}->sqlite_last_insert_rowid(); | |||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | 1140 | $sth->finish(); | |||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 1140 | $self->{Graph_Attribute}{ $id } = $value; | |||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | 978 | ▶ | sub _get_graph_attribute_value_id { | ||||||||||||||||||||||||||
|
Subroutine
_get_graph_attribute_value_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 743 | 978 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | 978 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 746 | SELECT rowid | ||||||||||||||||||||||||||||
| 747 | FROM Graph_Attribute | ||||||||||||||||||||||||||||
| 748 | WHERE attribute_name = ? | ||||||||||||||||||||||||||||
| 749 | }); | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | 978 | my ($rowid) = $self->{dbh}->selectrow_array($sth, {}, $name); | |||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | 978 | return $rowid; | |||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||
| 756 | 485 | ▶ | sub get_graph_attribute { | ||||||||||||||||||||||||||
|
Subroutine
get_graph_attribute: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 757 | 485 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | 485 | my $rowid = _get_graph_attribute_value_id($self, $name); | |||||||||||||||||||||||||||
| 760 | 485 | ▶ | return unless defined $rowid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 761 | 64 | return $self->{Graph_Attribute}{ $rowid }; | |||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | 509 | ▶ | sub get_graph_attributes { | ||||||||||||||||||||||||||
|
Subroutine
get_graph_attributes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 765 | 509 | my ($self) = @_; | |||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | 509 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 768 | SELECT | ||||||||||||||||||||||||||||
| 769 | rowid, | ||||||||||||||||||||||||||||
| 770 | attribute_name | ||||||||||||||||||||||||||||
| 771 | FROM Graph_Attribute | ||||||||||||||||||||||||||||
| 772 | }); | ||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||
| 774 | 509 | my @result; | |||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||
| 776 | 509 | for ($self->{dbh}->selectall_array($sth, {})) { | |||||||||||||||||||||||||||
| 777 | push @result, | ||||||||||||||||||||||||||||
| 778 | $_->[1], | ||||||||||||||||||||||||||||
| 779 | 179 | $self->{Graph_Attribute}{ $_->[0] }; | |||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | 509 | return { @result }; | |||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | 493 | ▶ | sub has_graph_attribute { | ||||||||||||||||||||||||||
|
Subroutine
has_graph_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 786 | 493 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 787 | 493 | my $rowid = _get_graph_attribute_value_id($self, $name); | |||||||||||||||||||||||||||
| 788 | 493 | return defined $rowid; | |||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||
| 791 | 489 | ▶ | sub set_graph_attributes { | ||||||||||||||||||||||||||
|
Subroutine
set_graph_attributes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 792 | 489 | my ($self, $attr) = @_; | |||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | 489 | $self->delete_graph_attributes(); | |||||||||||||||||||||||||||
| 795 | $self->set_graph_attribute($_, $attr->{$_}) | ||||||||||||||||||||||||||||
| 796 | 489 | for keys %$attr; | |||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | 1655 | ▶ | sub delete_graph_attribute { | ||||||||||||||||||||||||||
|
Subroutine
delete_graph_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 800 | 1655 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | 1655 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 803 | DELETE | ||||||||||||||||||||||||||||
| 804 | FROM Graph_Attribute | ||||||||||||||||||||||||||||
| 805 | WHERE attribute_name = ? | ||||||||||||||||||||||||||||
| 806 | }); | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | 1655 | $sth->execute($name); | |||||||||||||||||||||||||||
| 809 | 1655 | $sth->finish(); | |||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||
| 812 | 477 | ▶ | sub get_graph_attribute_names { | ||||||||||||||||||||||||||
|
Subroutine
get_graph_attribute_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 813 | 477 | my ($self) = @_; | |||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||
| 815 | 477 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 816 | SELECT attribute_name | ||||||||||||||||||||||||||||
| 817 | FROM Graph_Attribute | ||||||||||||||||||||||||||||
| 818 | }); | ||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | 477 | return map { @$_ } $self->{dbh}->selectall_array($sth); | |||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | 986 | ▶ | sub delete_graph_attributes { | ||||||||||||||||||||||||||
|
Subroutine
delete_graph_attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 824 | 986 | my ($self) = @_; | |||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||
| 826 | 986 | my $sth = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 827 | DELETE | ||||||||||||||||||||||||||||
| 828 | FROM Graph_Attribute | ||||||||||||||||||||||||||||
| 829 | }); | ||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||
| 831 | 986 | $sth->execute(); | |||||||||||||||||||||||||||
| 832 | 986 | $sth->finish(); | |||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | ##################################################################### | ||||||||||||||||||||||||||||
| 836 | # Extensions not provided by Graph::Directed | ||||||||||||||||||||||||||||
| 837 | ##################################################################### | ||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | 2 | ▶ | sub _copy_vertices_edges_attributes { | ||||||||||||||||||||||||||
|
Subroutine
_copy_vertices_edges_attributes: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 840 | 2 | my ($lhs, $rhs) = @_; | |||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||
| 842 | # copy vertices | ||||||||||||||||||||||||||||
| 843 | 2 | $rhs->add_vertices($lhs->vertices); | |||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||
| 845 | # copy edges | ||||||||||||||||||||||||||||
| 846 | 2 | $rhs->add_edges($lhs->edges); | |||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | # TODO(bh): use new plural methods instead | ||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | # copy graph attributes | ||||||||||||||||||||||||||||
| 851 | 2 | for my $n ($lhs->get_graph_attribute_names) { | |||||||||||||||||||||||||||
| 852 | 0 | $rhs->set_graph_attribute($n, | |||||||||||||||||||||||||||
| 853 | $lhs->get_graph_attribute($n)); | ||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | # copy vertex attributes | ||||||||||||||||||||||||||||
| 857 | 2 | for my $v ($lhs->vertices) { | |||||||||||||||||||||||||||
| 858 | 4 | for my $n ($lhs->get_vertex_attribute_names($v)) { | |||||||||||||||||||||||||||
| 859 | 0 | $rhs->set_vertex_attribute($v, $n, | |||||||||||||||||||||||||||
| 860 | $lhs->get_vertex_attribute($v, $n)); | ||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||
| 864 | # copy edge attributes | ||||||||||||||||||||||||||||
| 865 | 2 | for my $e ($lhs->edges) { | |||||||||||||||||||||||||||
| 866 | 2 | my ($src, $dst) = @$e; | |||||||||||||||||||||||||||
| 867 | 2 | for my $n ($lhs->get_edge_attribute_names($src, $dst)) { | |||||||||||||||||||||||||||
| 868 | 2 | $rhs->set_edge_attribute($src, $dst, $n, | |||||||||||||||||||||||||||
| 869 | $lhs->get_edge_attribute($src, $dst, $n)); | ||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||
| 874 | 1 | ▶ | sub feather_export_to { | ||||||||||||||||||||||||||
|
Subroutine
feather_export_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 875 | 1 | my ($self, $target) = @_; | |||||||||||||||||||||||||||
| 876 | 1 | _copy_vertices_edges_attributes($self, $target); | |||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | 1 | ▶ | sub feather_import_from { | ||||||||||||||||||||||||||
|
Subroutine
feather_import_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 880 | 1 | my ($self, $source) = @_; | |||||||||||||||||||||||||||
| 881 | 1 | _copy_vertices_edges_attributes($source, $self); | |||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||
| 884 | 0 | ▶ | sub _feather_restore_from_file { | ||||||||||||||||||||||||||
|
Subroutine
_feather_restore_from_file: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 885 | 0 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||
| 887 | 0 | $self->{dbh}->begin_work(); | |||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | 0 | $self->{dbh}->sqlite_backup_from_file($path); | |||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||
| 891 | 0 | my $sth1 = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 892 | PRAGMA application_id | ||||||||||||||||||||||||||||
| 893 | }); | ||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||
| 895 | 0 | my ($application_id) = $self->{dbh}->selectrow_array($sth1); | |||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||
| 897 | 0 | my $sth2 = $self->_prepare(q{ | |||||||||||||||||||||||||||
| 898 | PRAGMA user_version | ||||||||||||||||||||||||||||
| 899 | }); | ||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | 0 | my ($user_version) = $self->{dbh}->selectrow_array($sth2); | |||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | 0 | ▶ | die "$path was not created by this version of Graph::Feather" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$application_id eq $Graph::Feather::APPLICATION_ID and $user_version eq $Graph::Feather::VERSION_INT
MC/DC0%0/2
$application_id eq $Graph::Feather::APPLICATION_ID and $user_version eq $Graph::Feather::VERSION_INT
$application_id eq $Graph::Feather::APPLICATION_ID
$user_version eq $Graph::Feather::VERSION_INT
Truth table0%0/3
A and B
A= $application_id eq $Graph::Feather::APPLICATION_IDB= $user_version eq $Graph::Feather::VERSION_INT
| |||||||||||||||||||||||||||||
| 904 | unless $application_id eq $APPLICATION_ID | ||||||||||||||||||||||||||||
| 905 | and $user_version eq $VERSION_INT; | ||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | 0 | $self->{dbh}->commit(); | |||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||
| 909 | # The following is needed because attribute values have a | ||||||||||||||||||||||||||||
| 910 | # dual life to support Perl references as attribute values. | ||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||
| 912 | 0 | $self->set_graph_attribute(@$_) for | |||||||||||||||||||||||||||
| 913 | $self->{dbh}->selectall_array(q{ | ||||||||||||||||||||||||||||
| 914 | SELECT attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 915 | FROM Graph_Attribute}); | ||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | 0 | $self->set_vertex_attribute(@$_) for | |||||||||||||||||||||||||||
| 918 | $self->{dbh}->selectall_array(q{ | ||||||||||||||||||||||||||||
| 919 | SELECT vertex, attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 920 | FROM Vertex_Attribute}); | ||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||
| 922 | 0 | $self->set_edge_attribute(@$_) for | |||||||||||||||||||||||||||
| 923 | $self->{dbh}->selectall_array(q{ | ||||||||||||||||||||||||||||
| 924 | SELECT src, dst, attribute_name, attribute_value | ||||||||||||||||||||||||||||
| 925 | FROM Edge_Attribute}); | ||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | 4 | 1; | |||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||
| 930 | __END__ | ||||||||||||||||||||||||||||