lib/Data/TagDB/Cloudlet.pm

filter: Statementstmt 30.1% 16 / 53 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.4% 5 / 13 Podpod 100% 8 / 8 totaltotal 33.7% 29 / 86 CC 6 SCAR 27.1
CC
6
Cov
25%
new
42.0
db
2.0
roots
2.0
CRAP 15.1
« lib/Data/TagDB/LinkIterator.pm ↑ Summary lib/Data/TagDB/Exporter.pm »
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"} // []
l!l
00
MC/DC0%0/1
delete $opts{"root"} // []
delete $opts{"root"}
Truth table0%0/2
A
A= delete $opts{"root"}
Aresult
11
00
24 0 ▶ my $entry = delete($opts{entry}) // [];
Condition0%0/2
delete $opts{"entry"} // []
l!l
00
MC/DC0%0/1
delete $opts{"entry"} // []
delete $opts{"entry"}
Truth table0%0/2
A
A= delete $opts{"entry"}
Aresult
11
00
25  
26 0 ▶ croak 'No database given' unless defined $opts{db};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"db"} 0 0 0
27  
28 0 ▶ $root = [$root] unless ref($root) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $root eq "ARRAY" 0 0 0
29 0 ▶ $entry = [$entry] unless ref($entry) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry eq "ARRAY" 0 0 0
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__
« lib/Data/TagDB/LinkIterator.pm ↑ Summary lib/Data/TagDB/Exporter.pm »