| 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
| |||||||||||||||||||||
| 41 | 0 | ▶ | croak 'Invalid type for key: '.$key unless eval {$v->isa($_types{$key})}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | ▶ | $storage->{$key} //= $v; | ||||||||||||||||||
|
Condition0%0/3
$storage->{$key} //= $v
MC/DC0%0/2
$storage->{$key} //= $v
$storage->{$key}
$v
Truth table0%0/3
A //= B
A= $storage->{$key}B= $v
| |||||||||||||||||||||
| 43 | 0 | ▶ | croak 'Missmatch for key: '.$key unless $storage->{$key} == $v; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ▶ | weaken($storage->{$key}) if $weak; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | croak 'Stray options passed' if scalar keys %opts; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | foreach my $value (values %{$storage}) { | |||||||||||||||||||
| 60 | 0 | ▶ | next unless defined $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | ▶ | return $value if $value->isa($name); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | if (defined(my $parent = $storage->{parent})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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"} //= {}
MC/DC0%0/1
$self->{"subobjects"} //= {}
$self->{"subobjects"}
Truth table0%0/2
A
A= $self->{"subobjects"}
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||