Identifier/Interface/Subobjects.pm

filter: Statementstmt 88.4% 46 / 52 Branchbran 54.5% 12 / 22 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 79.3% 77 / 97 CC 16 SCAR 20.4
CC
16
Cov
78%
so_get
15.1
so_attach
8.2
_subobject_provider
2.0
CRAP 7.7
« Identifier/Wellknown.pm ↑ Summary Identifier/Interface/Userdata.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 5 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use parent 'Data::Identifier::Interface::Userdata';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 our $VERSION = v0.39;
20  
21 5 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 2 ▶sub so_attach {
Subroutine so_attach: called CC=8 SCAR=21.1
Pod documented
32 2 my ($self, %opts) = @_;
33 2 my $storage = $self->_subobject_provider;
34 2 my $weak = delete $opts{weak};
35  
36 2 delete $opts{allow_registered}; # for future use, not yet documented.
37  
38 2 foreach my $key (keys %_types) {
39 12 my $v = delete $opts{$key};
40 12 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 10 2 12
41 2 ▶ croak 'Invalid type for key: '.$key unless eval {$v->isa($_types{$key})};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $v->isa($_types{$key}) } } 0 2 2
42 2 ▶ $storage->{$key} //= $v;
Condition66%2/3
$storage->{$key} //= $v
l!l&&r!l&&!r
110
MC/DC0%0/2
$storage->{$key} //= $v
$storage->{$key} $v
Truth table66%2/3
A //= B
A= $storage->{$key}B= $v
ABresult
1X1
011
000
43 2 ▶ croak 'Missmatch for key: '.$key unless $storage->{$key} == $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $storage->{$key} == $v 0 2 2
44 2 ▶ weaken($storage->{$key}) if $weak;
Branch: 1 branch
BranchTrueFalseTotal
if $weak 1 1 2
45 }
46  
47 2 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 2 2
48  
49 2 return $self;
50 }
51  
52  
53 3 ▶sub so_get {
Subroutine so_get: called CC=8 SCAR=27.1
Pod documented
54 3 my ($self, $name, %opts) = @_;
55 3 my $storage = $self->_subobject_provider;
56  
57 3 ▶ return $storage->{$name} if defined $storage->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $storage->{$name} 2 1 3
58  
59 1 foreach my $value (values %{$storage}) {
60 1 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 0 1
61 0 ▶ return $value if $value->isa($name);
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa($name) 0 0 0
62 }
63  
64 1 ▶ if (defined(my $parent = $storage->{parent})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $storage->{"parent"})) 0 1 1
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 1 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 1 0 1
71 0 croak 'No such subobject attached';
72 }
73  
74  
75 5 ▶sub _subobject_provider {
Subroutine _subobject_provider: called CC=2 SCAR=6.9
76 5 my ($self) = @_;
77 5 ▶ return $self->{subobjects} //= {};
Condition100%2/2
$self->{"subobjects"} //= {}
l!l
41
MC/DC100%1/1
$self->{"subobjects"} //= {}
$self->{"subobjects"}
Truth table100%2/2
A
A= $self->{"subobjects"}
Aresult
11
00
78 }
79  
80  
81 2 ▶sub so_new {
Subroutine so_new: called CC=1 SCAR=0.0
Pod documented
82 2 my ($pkg) = @_;
83 2 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 5 1;
93  
94 __END__
« Identifier/Wellknown.pm ↑ Summary Identifier/Interface/Userdata.pm »