Identifier/Interface/Subobjects.pm

filter: Statementstmt 38.4% 20 / 52 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 54.5% 6 / 11 Podpod 100% 4 / 4 totaltotal 30.9% 30 / 97 CC 16 SCAR 38.1
CC
16
Cov
25%
so_attach
72.0
so_get
72.0
_subobject_provider
6.0
CRAP 45.2
« Identifier/Cloudlet.pm ↑ Summary Identifier/Interface/Known.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::Interface::Subobjects;
9  
10 4 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use parent 'Data::Identifier::Interface::Userdata';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 our $VERSION = v0.38;
20  
21 4 my %_types = (
22 db => 'Data::TagDB',
23 extractor => 'Data::URIID',
24 tagmap => 'Data::TagMap',
25 fii => 'File::Information',
26 store => 'File::FStore',
27 parent => __PACKAGE__,
28 );
29  
30  
31 0 ▶sub so_attach {
Subroutine so_attach: not called CC=8 SCAR=42.8
Pod documented
32 0 my ($self, %opts) = @_;
33 0 my $storage = $self->_subobject_provider;
34 0 my $weak = delete $opts{weak};
35  
36 0 delete $opts{allow_registered}; # for future use, not yet documented.
37  
38 0 foreach my $key (keys %_types) {
39 0 my $v = delete $opts{$key};
40 0 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
41 0 ▶ croak 'Invalid type for key: '.$key unless eval {$v->isa($_types{$key})};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $v->isa($_types{$key}) } } 0 0 0
42 0 ▶ $storage->{$key} //= $v;
Condition0%0/3
$storage->{$key} //= $v
l!l&&r!l&&!r
000
MC/DC0%0/2
$storage->{$key} //= $v
$storage->{$key} $v
Truth table0%0/3
A //= B
A= $storage->{$key}B= $v
ABresult
1X1
011
000
43 0 ▶ croak 'Missmatch for key: '.$key unless $storage->{$key} == $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $storage->{$key} == $v 0 0 0
44 0 ▶ weaken($storage->{$key}) if $weak;
Branch: 1 branch
BranchTrueFalseTotal
if $weak 0 0 0
45 }
46  
47 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
48  
49 0 return $self;
50 }
51  
52  
53 0 ▶sub so_get {
Subroutine so_get: not called CC=8 SCAR=42.8
Pod documented
54 0 my ($self, $name, %opts) = @_;
55 0 my $storage = $self->_subobject_provider;
56  
57 0 ▶ return $storage->{$name} if defined $storage->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $storage->{$name} 0 0 0
58  
59 0 foreach my $value (values %{$storage}) {
60 0 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
61 0 ▶ return $value if $value->isa($name);
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa($name) 0 0 0
62 }
63  
64 0 ▶ if (defined(my $parent = $storage->{parent})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $storage->{"parent"})) 0 0 0
65 0 local $storage->{parent} = undef;
66 0 my $v = $parent->so_get($name, default => undef);
67 0 ▶ return $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
68 }
69  
70 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
71 0 croak 'No such subobject attached';
72 }
73  
74  
75 0 ▶sub _subobject_provider {
Subroutine _subobject_provider: not called CC=2 SCAR=17.9
76 0 my ($self) = @_;
77 0 ▶ return $self->{subobjects} //= {};
Condition0%0/2
$self->{"subobjects"} //= {}
l!l
00
MC/DC0%0/1
$self->{"subobjects"} //= {}
$self->{"subobjects"}
Truth table0%0/2
A
A= $self->{"subobjects"}
Aresult
11
00
78 }
79  
80  
81 0 ▶sub so_new {
Subroutine so_new: not called CC=1 SCAR=6.9
Pod documented
82 0 my ($pkg) = @_;
83 0 return bless {};
84 }
85  
86  
87  
88 0 ▶sub KEYS {
Subroutine KEYS: not called CC=1 SCAR=6.9
Pod documented
89 0 return keys %_types;
90 }
91  
92 4 1;
93  
94 __END__
« Identifier/Cloudlet.pm ↑ Summary Identifier/Interface/Known.pm »