| 1 | # Copyright (c) 2024-2026 Philipp Schafft | ||||||||||||
| 2 | |||||||||||||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||||||||||||
| 4 | |||||||||||||
| 5 | # ABSTRACT: Work with Tag databases | ||||||||||||
| 6 | |||||||||||||
| 7 | package Data::TagDB::Cloudlet; | ||||||||||||
| 8 | |||||||||||||
| 9 | 4 | ▶ | use v5.16; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 4 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 4 | ▶ | use Data::TagDB::Iterator; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | 4 | our $VERSION = v0.16; | |||||||||||
| 18 | |||||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 22 | 0 | my ($pkg, %opts) = @_; | |||||||||||
| 23 | 0 | ▶ | my $root = delete($opts{root}) // []; | ||||||||||
|
Condition0%0/2
delete $opts{"root"} // []
MC/DC0%0/1
delete $opts{"root"} // []
delete $opts{"root"}
Truth table0%0/2
A
A= delete $opts{"root"}
| |||||||||||||
| 24 | 0 | ▶ | my $entry = delete($opts{entry}) // []; | ||||||||||
|
Condition0%0/2
delete $opts{"entry"} // []
MC/DC0%0/1
delete $opts{"entry"} // []
delete $opts{"entry"}
Truth table0%0/2
A
A= delete $opts{"entry"}
| |||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | croak 'No database given' unless defined $opts{db}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | $root = [$root] unless ref($root) eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | ▶ | $entry = [$entry] unless ref($entry) eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | |||||||||||||
| 31 | $opts{entries} = { | ||||||||||||
| 32 | 0 | (map {$_->dbid => undef} @{$entry}), | |||||||||||
| 33 | 0 | (map {$_->dbid => 1} @{$root}), | |||||||||||
| 34 | }; | ||||||||||||
| 35 | |||||||||||||
| 36 | 0 | return bless \%opts, $pkg; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | sub db { | ||||||||||
|
Subroutine
db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||||
| 42 | 0 | return $self->{db}; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | sub roots { | ||||||||||
|
Subroutine
roots: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||
| 48 | 0 | my Data::TagDB $db = $self->db; | |||||||||||
| 49 | 0 | my $entries = $self->{entries}; | |||||||||||
| 50 | |||||||||||||
| 51 | 0 | return map {$db->tag_by_dbid($_)} grep {$entries->{$_}} keys %{$entries}; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub entries { | ||||||||||
|
Subroutine
entries: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 56 | 0 | my ($self) = @_; | |||||||||||
| 57 | 0 | my Data::TagDB $db = $self->db; | |||||||||||
| 58 | 0 | my $entries = $self->{entries}; | |||||||||||
| 59 | |||||||||||||
| 60 | 0 | return map {$db->tag_by_dbid($_)} keys %{$entries}; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | #@returns Data::TagDB::Iterator | ||||||||||||
| 65 | 0 | ▶ | sub roots_iterator { | ||||||||||
|
Subroutine
roots_iterator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 66 | 0 | my ($self) = @_; | |||||||||||
| 67 | 0 | my @entries = $self->roots; | |||||||||||
| 68 | 0 | return Data::TagDB::Iterator->from_array(\@entries, db => $self->db); | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | |||||||||||||
| 72 | #@returns Data::TagDB::Iterator | ||||||||||||
| 73 | 0 | ▶ | sub entries_iterator { | ||||||||||
|
Subroutine
entries_iterator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||||
| 75 | 0 | my @entries = $self->entries; | |||||||||||
| 76 | 0 | return Data::TagDB::Iterator->from_array(\@entries, db => $self->db); | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | |||||||||||||
| 80 | 0 | ▶ | sub is_root { | ||||||||||
|
Subroutine
is_root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 81 | 0 | my ($self, $tag) = @_; | |||||||||||
| 82 | 0 | return $self->{entries}{$tag->dbid}; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | 0 | ▶ | sub is_entry { | ||||||||||
|
Subroutine
is_entry: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 87 | 0 | my ($self, $tag) = @_; | |||||||||||
| 88 | 0 | return exists $self->{entries}{$tag->dbid}; | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | # ---- Private helpers ---- | ||||||||||||
| 92 | |||||||||||||
| 93 | 4 | 1; | |||||||||||
| 94 | |||||||||||||
| 95 | __END__ | ||||||||||||