Identifier/Cloudlet.pm

filter: Statementstmt 55.6% 59 / 106 Branchbran 25.0% 11 / 44 Conditioncond 9.6% 5 / 52 MC/DCmcdc 6.6% 2 / 30 Subroutinesub 84.6% 11 / 13 Podpod 100% 7 / 7 totaltotal 37.7% 95 / 252 CC 48 SCAR 46.1
CC
48
Cov
37%
as
210.0
new
120.5
add_entry
20.0
CRAP 100.1
« Identifier/Generate.pm ↑ Summary Identifier/Interface/Subobjects.pm »
1 # Copyright (c) 2023-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: format independent identifier object
6  
7  
8 package Data::Identifier::Cloudlet;
9  
10 2 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use parent qw(Data::Identifier::Interface::Userdata Data::Identifier::Interface::Subobjects);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Data::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our $VERSION = v0.38;
21  
22 2 my @_old_subobjects = qw(db extractor fii store);
23  
24  
25 5 ▶sub new {
Subroutine new: called CC=24 SCAR=47.9
Pod documented
26 5 my ($pkg, %opts) = @_;
27 5 my $self = bless {}, $pkg;
28  
29 5 ▶ if (defined(my $from = delete($opts{from}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $from = delete $opts{"from"})) 0 5 5
30 0 ▶ if (defined(delete($opts{root})) || defined(delete($opts{entry}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined delete $opts{"root"} or defined delete $opts{"entry"}) 0 0 0
Condition0%0/3
defined delete $opts{"root"} or defined delete $opts{"entry"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined delete $opts{"root"} or defined delete $opts{"entry"}
defined delete $opts{"root"} defined delete $opts{"entry"}
Truth table0%0/3
A or B
A= defined delete $opts{"root"}B= defined delete $opts{"entry"}
ABresult
1X1
011
000
31 0 croak 'root and entry given with from';
32 }
33  
34 0 ▶ if (eval {$from->isa(__PACKAGE__)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $from->isa(__PACKAGE__) } }) 0 0 0
35 0 ▶ $self->so_attach($_ => $from->so_get($_, default => undef, no_defaults => 1) // next) foreach @_old_subobjects;
Condition0%0/2
$from->so_get($_, "default", undef, "no_defaults", 1) // (next)
l!l
00
MC/DC0%0/1
$from->so_get($_, "default", undef, "no_defaults", 1) // (next)
$from->so_get($_, "default", undef, "no_defaults", 1)
Truth table0%0/2
A
A= $from->so_get($_, "default", undef, "no_defaults", 1)
Aresult
11
00
36 0 $self->so_attach(parent => $from);
37  
38 0 $opts{root} = [$from->roots];
39 0 $opts{entry} = [$from->entries];
40 }
41  
42 0 ▶ if (!ref($from) || ref($from) eq 'ARRAY' || eval {$from->can('ise')}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $from or ref $from eq "ARRAY" or eval { do { $from->can("ise") } }) 0 0 0
Condition0%0/6
not ref $from or ref $from eq "ARRAY" or eval { do { $from->can("ise") } }
l!l&&r!l&&!r
000
not ref $from or ref $from eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
not ref $from or ref $from eq "ARRAY" or eval { do { $from->can("ise") } }
not ref $from ref $from eq "ARRAY" eval { do { $from->can("ise") } }
Truth table0%0/4
not(A) or B or C
A= not ref $fromB= ref $from eq "ARRAY"C= eval { do { $from->can("ise") } }
ABCresult
1XX1
01X1
0011
0000
43 0 $opts{root} = $from;
44 }
45  
46 0 ▶ croak 'Unknown/Unsupported from' unless defined $opts{root};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"root"} 0 0 0
47 }
48  
49 5 foreach my $key (@_old_subobjects) {
50 20 ▶ my $v = delete($opts{$key}) // next;
Condition50%1/2
delete $opts{$key} // (next)
l!l
020
MC/DC0%0/1
delete $opts{$key} // (next)
delete $opts{$key}
Truth table50%1/2
A
A= delete $opts{$key}
Aresult
11
00
51  
52 0 $self->so_attach($key => $v);
53 }
54  
55 5 ▶ if (defined(my $so = delete $opts{so})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $so = delete $opts{"so"})) 0 5 5
56 0 require Data::Identifier::Interface::Subobjects; # Is this required?
57 0 ▶ $self->so_attach($_ => $so->so_get($_, default => undef) // next) foreach Data::Identifier::Interface::Subobjects->KEYS;
Condition0%0/2
$so->so_get($_, "default", undef) // (next)
l!l
00
MC/DC0%0/1
$so->so_get($_, "default", undef) // (next)
$so->so_get($_, "default", undef)
Truth table0%0/2
A
A= $so->so_get($_, "default", undef)
Aresult
11
00
58 }
59  
60 5 foreach my $key (qw(root entry)) {
61 10 ▶ my $v = delete($opts{$key}) // next;
Condition100%2/2
delete $opts{$key} // (next)
l!l
82
MC/DC100%1/1
delete $opts{$key} // (next)
delete $opts{$key}
Truth table100%2/2
A
A= delete $opts{$key}
Aresult
11
00
62  
63 8 ▶ $v = [$v] unless ref($v) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 7 1 8
64  
65 8 foreach my $s (@{$v}) {
66 9 ▶ unless (eval {$s->can('ise')}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $s->can("ise") } }) 0 9 9
67 0 $s = Data::Identifier->new(from => $s);
68 }
69 }
70  
71 8 $v = {map {$_->ise => $_} @{$v}};
72  
73 8 $self->{$key} = $v;
74 }
75  
76 5 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 5 5
77  
78 5 ▶ croak 'No root given' unless defined $self->{root};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"root"} 0 5 5
79  
80 5 ▶ $self->{entry} = {%{$self->{entry}//{}}, %{$self->{root}}};
Condition100%2/2
$self->{"entry"} // {}
l!l
32
MC/DC100%1/1
$self->{"entry"} // {}
$self->{"entry"}
Truth table100%2/2
A
A= $self->{"entry"}
Aresult
11
00
81  
82 5 return $self;
83 }
84  
85  
86 0 ▶sub as {
Subroutine as: not called CC=14 SCAR=53.5
Pod documented
87 0 my ($self, $as, %opts) = @_;
88 0 my %extra = %opts{@_old_subobjects};
89  
90 0 ▶ $as = $opts{rawtype} if $as eq 'raw' && defined($opts{rawtype});
Branch: 1 branch
BranchTrueFalseTotal
if $as eq "raw" and defined $opts{"rawtype"} 0 0 0
Condition0%0/3
$as eq "raw" and defined $opts{"rawtype"}
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "raw" and defined $opts{"rawtype"}
$as eq "raw" defined $opts{"rawtype"}
Truth table0%0/3
A and B
A= $as eq "raw"B= defined $opts{"rawtype"}
ABresult
0X0
100
111
91  
92 0 ▶ return $self if ($as =~ /^[A-Z]/ || $as =~ /::/) && eval {$self->isa($as)};
Branch: 1 branch
BranchTrueFalseTotal
if $as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } } 0 0 0
Condition0%0/6
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
!ll&&!rl&&r
000
$as =~ /^[A-Z]/u or $as =~ /::/u
l!l&&r!l&&!r
000
MC/DC0%0/3
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
$as =~ /^[A-Z]/u $as =~ /::/u eval { do { $self->isa($as) } }
Truth table0%0/5
A or B and C
A= $as =~ /^[A-Z]/uB= $as =~ /::/uC= eval { do { $self->isa($as) } }
ABCresult
00X0
1X00
0100
1X11
0111
93  
94 0 ▶ if (eval {$self->isa(__PACKAGE__)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $self->isa(__PACKAGE__) } }) 0 0 0
95 0 ▶ $extra{so} //= $self;
Condition0%0/3
$extra{"so"} //= $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$extra{"so"} //= $self
$extra{"so"} $self
Truth table0%0/3
A //= B
A= $extra{"so"}B= $self
ABresult
1X1
011
000
96 }
97  
98 0 ▶ if (!ref($self) || ref($self) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self or ref $self eq "ARRAY") 0 0 0
Condition0%0/3
not ref $self or ref $self eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $self or ref $self eq "ARRAY"
not ref $self ref $self eq "ARRAY"
Truth table0%0/3
not(A) or B
A= not ref $selfB= ref $self eq "ARRAY"
ABresult
1X1
011
000
99 0 $self = __PACKAGE__->new(root => $self, %extra);
100 0 ▶ return $self if ($as =~ /^[A-Z]/ || $as =~ /::/) && eval {$self->isa($as)};
Branch: 1 branch
BranchTrueFalseTotal
if $as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } } 0 0 0
Condition0%0/6
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
!ll&&!rl&&r
000
$as =~ /^[A-Z]/u or $as =~ /::/u
l!l&&r!l&&!r
000
MC/DC0%0/3
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
$as =~ /^[A-Z]/u $as =~ /::/u eval { do { $self->isa($as) } }
Truth table0%0/5
A or B and C
A= $as =~ /^[A-Z]/uB= $as =~ /::/uC= eval { do { $self->isa($as) } }
ABCresult
00X0
1X00
0100
1X11
0111
101 }
102  
103 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
104 0 croak 'Unknown/Unsupported as: '.$as;
105 }
106  
107  
108 4 ▶sub roots {
Subroutine roots: called CC=4 SCAR=22.6
Pod documented
109 4 my ($self, %opts) = @_;
110  
111 4 ▶ if (defined $opts{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"as"}) 0 4 4
112 0 ▶ my %extra = map {$_ => ($opts{$_} // $self->so_get($_, default => undef, no_defaults => 1))} @_old_subobjects;
Condition0%0/3
$opts{$_} // $self->so_get($_, "default", undef, "no_defaults", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{$_} // $self->so_get($_, "default", undef, "no_defaults", 1)
$opts{$_} $self->so_get($_, "default", undef, "no_defaults", 1)
Truth table0%0/3
A // B
A= $opts{$_}B= $self->so_get($_, "default", undef, "no_defaults", 1)
ABresult
1X1
011
000
113 return map {$_->Data::Identifier::as(
114 $opts{as},
115 0 ▶ so => $opts{so} // $self,
Condition0%0/3
$opts{"so"} // $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"so"} // $self
$opts{"so"} $self
Truth table0%0/3
A // B
A= $opts{"so"}B= $self
ABresult
1X1
011
000
116 %extra,
117 0 )} values %{$self->{root}};
118 }
119  
120 4 return values %{$self->{root}};
121 }
122  
123  
124 4 ▶sub entries {
Subroutine entries: called CC=4 SCAR=22.6
Pod documented
125 4 my ($self, %opts) = @_;
126  
127 4 ▶ if (defined $opts{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"as"}) 0 4 4
128 0 ▶ my %extra = map {$_ => ($opts{$_} // $self->so_get($_, default => undef, no_defaults => 1))} @_old_subobjects;
Condition0%0/3
$opts{$_} // $self->so_get($_, "default", undef, "no_defaults", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{$_} // $self->so_get($_, "default", undef, "no_defaults", 1)
$opts{$_} $self->so_get($_, "default", undef, "no_defaults", 1)
Truth table0%0/3
A // B
A= $opts{$_}B= $self->so_get($_, "default", undef, "no_defaults", 1)
ABresult
1X1
011
000
129 return map {$_->Data::Identifier::as(
130 $opts{as},
131 0 ▶ so => $opts{so} // $self,
Condition0%0/3
$opts{"so"} // $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"so"} // $self
$opts{"so"} $self
Truth table0%0/3
A // B
A= $opts{"so"}B= $self
ABresult
1X1
011
000
132 %extra,
133 0 )} values %{$self->{root}};
134 }
135  
136 4 return values %{$self->{entry}};
137 }
138  
139  
140 3 ▶sub is_root {
Subroutine is_root: called CC=2 SCAR=7.0
Pod documented
141 3 my ($self, $tag) = @_;
142 3 ▶ $tag = Data::Identifier->new(from => $tag) unless eval {$tag->can('ise')};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $tag->can("ise") } } 0 3 3
143 3 return exists $self->{root}{$tag->ise};
144 }
145  
146  
147 3 ▶sub is_entry {
Subroutine is_entry: called CC=2 SCAR=7.0
Pod documented
148 3 my ($self, $tag) = @_;
149 3 ▶ $tag = Data::Identifier->new(from => $tag) unless eval {$tag->can('ise')};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $tag->can("ise") } } 0 3 3
150 3 return exists $self->{entry}{$tag->ise};
151 }
152  
153  
154 0 ▶sub add_entry {
Subroutine add_entry: not called CC=4 SCAR=30.0
Pod documented
155 0 my ($self, @entries) = @_;
156  
157 0 foreach my $entry (@entries) {
158 0 ▶ unless (eval {$entry->can('ise')}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $entry->can("ise") } }) 0 0 0
159 0 $entry = Data::Identifier->new(from => $entry);
160 }
161 0 ▶ next if exists $self->{entry}{$entry->ise};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"entry"}{$entry->ise} 0 0 0
162 0 $self->{entry}{$entry->ise} = $entry;
163 }
164 }
165  
166 2 1;
167  
168 __END__
« Identifier/Generate.pm ↑ Summary Identifier/Interface/Subobjects.pm »