| 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::Tag; | ||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use List::Util qw(any all); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 4 | our $VERSION = v0.16; | |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use parent qw(Data::Identifier::Interface::Simple Data::TagDB::Base); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Data::Identifier v0.34; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | my %_key_to_data_identifier = ( | ||||||||||||||||||||||||||||||||||||||
| 24 | 'small-identifier' => 'sid', | ||||||||||||||||||||||||||||||||||||||
| 25 | 4 | (map {$_ => $_} qw(uuid oid uri)), | |||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub dbid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dbid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return 0 unless defined $self; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $self->{dbid}; | |||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _get_id { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_id: not called CC=30 SCAR=68.4
| |||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $key = $opts{_key}; | |||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $value = $self->{$key} //= eval { $self->_get_data(_tag_simple_identifier => $key => $self->dbid) }; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{$key} //= eval {
do {
$self->_get_data("_tag_simple_identifier", $key, $self->dbid)
}
}
MC/DC0%0/2
$self->{$key} //= eval {
do {
$self->_get_data("_tag_simple_identifier", $key, $self->dbid)
}
}
$self->{$key}
eval {
do {
$self->_get_data("_tag_simple_identifier", $key, $self->dbid)
}
}
Truth table0%0/3
A //= B
A= $self->{$key}B= eval {
do {
$self->_get_data("_tag_simple_identifier", $key, $self->dbid)
}
}
| |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $curtype; | |||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (!defined($value) && !$opts{no_defaults}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value or $opts{"no_defaults"}
MC/DC0%0/2
defined $value or $opts{"no_defaults"}
defined $value
$opts{"no_defaults"}
Truth table0%0/3
A or B
A= defined $valueB= $opts{"no_defaults"}
| |||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (defined $self->{$key.'_defaults'}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $value = $self->{$key.'_defaults'}; | |||||||||||||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $id; | |||||||||||||||||||||||||||||||||||||
| 48 | my $backup_key; | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | foreach my $backup_key_try (qw(uuid oid uri small-identifier)) { | |||||||||||||||||||||||||||||||||||||
| 50 | 0 | $id = eval { $self->_get_data(_tag_simple_identifier => $backup_key_try => $self->dbid) }; | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (defined $id) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $backup_key = $backup_key_try; | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | last; | |||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (defined($id) && defined($backup_key)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $id and defined $backup_key
MC/DC0%0/2
defined $id and defined $backup_key
defined $id
defined $backup_key
Truth table0%0/3
A and B
A= defined $idB= defined $backup_key
| |||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (defined(my $type = $_key_to_data_identifier{$backup_key})) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $did = Data::Identifier->new($type => $id); | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $func = $did->can($_key_to_data_identifier{$key} // ''); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_key_to_data_identifier{$key} // ""
MC/DC0%0/1
$_key_to_data_identifier{$key} // ""
$_key_to_data_identifier{$key}
Truth table0%0/2
A
A= $_key_to_data_identifier{$key}
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (defined $func) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $value = eval {$did->$func()}; | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | $curtype = $key; | |||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||
| 64 | ▶ | } elsif ($backup_key eq 'uuid' && $key eq 'uri') { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$backup_key eq "uuid" and $key eq "uri"
MC/DC0%0/2
$backup_key eq "uuid" and $key eq "uri"
$backup_key eq "uuid"
$key eq "uri"
Truth table0%0/3
A and B
A= $backup_key eq "uuid"B= $key eq "uri"
| |||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $value = sprintf('urn:uuid:%s', $id); | |||||||||||||||||||||||||||||||||||||
| 66 | ▶ | } elsif ($backup_key eq 'oid' && $key eq 'uri') { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$backup_key eq "oid" and $key eq "uri"
MC/DC0%0/2
$backup_key eq "oid" and $key eq "uri"
$backup_key eq "oid"
$key eq "uri"
Truth table0%0/3
A and B
A= $backup_key eq "oid"B= $key eq "uri"
| |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $value = sprintf('urn:oid:%s', $id); | |||||||||||||||||||||||||||||||||||||
| 68 | ▶ | } elsif ($backup_key eq 'small-identifier' && $key eq 'uri') { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$backup_key eq "small-identifier" and $key eq "uri"
MC/DC0%0/2
$backup_key eq "small-identifier" and $key eq "uri"
$backup_key eq "small-identifier"
$key eq "uri"
Truth table0%0/3
A and B
A= $backup_key eq "small-identifier"B= $key eq "uri"
| |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $u = URI->new("https://uriid.org/"); | |||||||||||||||||||||||||||||||||||||
| 70 | 0 | $u->path_segments('', 'sid', $id); | |||||||||||||||||||||||||||||||||||||
| 71 | 0 | $value = $u->as_string; | |||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $self->{$key.'_defaults'} = $value if defined $value; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $as = $opts{as} // $key; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"as"} // $key
MC/DC0%0/2
$opts{"as"} // $key
$opts{"as"}
$key
Truth table0%0/3
A // B
A= $opts{"as"}B= $key
| |||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $curtype //= $key; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$curtype //= $key
MC/DC0%0/2
$curtype //= $key
$curtype
$key
Truth table0%0/3
A //= B
A= $curtypeB= $key
| |||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($as eq $key || $as eq 'raw') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$as eq $key or $as eq "raw"
MC/DC0%0/2
$as eq $key or $as eq "raw"
$as eq $key
$as eq "raw"
Truth table0%0/3
A or B
A= $as eq $keyB= $as eq "raw"
| |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||
| 85 | ▶ | } elsif ($as eq 'URI' && $curtype eq 'uri') { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$as eq "URI" and $curtype eq "uri"
MC/DC0%0/2
$as eq "URI" and $curtype eq "uri"
$as eq "URI"
$curtype eq "uri"
Truth table0%0/3
A and B
A= $as eq "URI"B= $curtype eq "uri"
| |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $self->{$key.'_URI'} //= URI->new($value); # convert and cache. | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$$self{$key . '_URI'} //= "URI"->new($value)
MC/DC0%0/2
$$self{$key . '_URI'} //= "URI"->new($value)
$$self{$key . '_URI'}
"URI"->new($value)
Truth table0%0/3
A //= B
A= $$self{$key . '_URI'}B= "URI"->new($value)
| |||||||||||||||||||||||||||||||||||||||
| 87 | ▶ | } elsif ($as eq 'Data::Identifier' && defined(my $type = $_key_to_data_identifier{$curtype})) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$as eq "Data::Identifier" and defined(my $type = $_key_to_data_identifier{$curtype})
MC/DC0%0/2
$as eq "Data::Identifier" and defined(my $type = $_key_to_data_identifier{$curtype})
$as eq "Data::Identifier"
defined(my $type = $_key_to_data_identifier{$curtype})
Truth table0%0/3
A and B
A= $as eq "Data::Identifier"B= defined(my $type = $_key_to_data_identifier{$curtype})
| |||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return Data::Identifier->new($type => $value, displayname => sub { $self->displayname(default => undef) }); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||
| 90 | 0 | croak 'Unsupported as option: '.$as; | |||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | croak 'No identifier of requested type'; | |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub uuid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
uuid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $self->_get_id(%opts, _key => 'uuid'); | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub oid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
oid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 104 | 0 | return $self->_get_id(%opts, _key => 'oid'); | |||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub uri { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return $self->_get_id(%opts, _key => 'uri', as => $opts{as} // 'URI'); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"as"} // "URI"
MC/DC0%0/1
$opts{"as"} // "URI"
$opts{"as"}
Truth table0%0/2
A
A= $opts{"as"}
| |||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub sid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
sid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $self->_get_id(%opts, _key => 'small-identifier'); | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub ise { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ise: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $has_default = exists $opts{default}; | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $val_default = delete $opts{default}; | |||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $val_no_defaults = delete $opts{no_defaults}; | |||||||||||||||||||||||||||||||||||||
| 121 | 0 | my @keys = qw(uuid oid uri); | |||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $opts{default} = undef; | |||||||||||||||||||||||||||||||||||||
| 125 | 0 | $opts{no_defaults} = 1; | |||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | foreach my $key (@keys) { | |||||||||||||||||||||||||||||||||||||
| 128 | 0 | $value = $self->_get_id(%opts, _key => $key); | |||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | last if defined $value; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return $value if defined $value; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | unless ($val_no_defaults) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 134 | # retry with defaults | ||||||||||||||||||||||||||||||||||||||
| 135 | 0 | delete $opts{default}; | |||||||||||||||||||||||||||||||||||||
| 136 | 0 | delete $opts{no_defaults}; | |||||||||||||||||||||||||||||||||||||
| 137 | 0 | foreach my $key (@keys) { | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $func = $self->can($key); | |||||||||||||||||||||||||||||||||||||
| 139 | 0 | $value = eval {$self->$func(%opts)}; | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | last if defined $value; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return $value if defined $value; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $val_default if $has_default; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | 0 | croak 'No ISE found or unsupported as-option'; | |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub displayname { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
displayname: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | unless (defined $self->{displayname}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $policies = [qw(british dash nospace lower noupper long)]; | |||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $wk = $db->wk; | |||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $asi = $wk->also_shares_identifier; | |||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $name; | |||||||||||||||||||||||||||||||||||||
| 160 | 0 | my @identifier_types = ( | |||||||||||||||||||||||||||||||||||||
| 161 | $wk->tagname, | ||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | 0 | foreach my $relation ( | |||||||||||||||||||||||||||||||||||||
| 165 | [qw(also_has_title)], | ||||||||||||||||||||||||||||||||||||||
| 166 | [qw(tagpool_title gamebook_has_title)], | ||||||||||||||||||||||||||||||||||||||
| 167 | ) { | ||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $relation = [grep {defined} map {eval{$wk->_call($_)}} @{$relation}]; | |||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | next unless scalar @{$relation}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $name = eval { | |||||||||||||||||||||||||||||||||||||
| 171 | 0 | _select_string( | |||||||||||||||||||||||||||||||||||||
| 172 | $policies, | ||||||||||||||||||||||||||||||||||||||
| 173 | $db->metadata(tag => $self, relation => $relation)->collect('data', skip_died => 1), | ||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return $self->{displayname} = $name if defined($name) && length($name); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | 0 | foreach my $type (@identifier_types) { | |||||||||||||||||||||||||||||||||||||
| 180 | 0 | $name = eval { | |||||||||||||||||||||||||||||||||||||
| 181 | 0 | _select_string( | |||||||||||||||||||||||||||||||||||||
| 182 | $policies, | ||||||||||||||||||||||||||||||||||||||
| 183 | $db->metadata(tag => $self, relation => $asi, type => $type)->collect('data', skip_died => 1), | ||||||||||||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||||||||||||
| 185 | }; | ||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $self->{displayname} = $name if defined($name) && length($name); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | unless ($opts{no_defaults} || defined($self->{displayname_defaults})) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"no_defaults"} or defined $self->{"displayname_defaults"}
MC/DC0%0/2
$opts{"no_defaults"} or defined $self->{"displayname_defaults"}
$opts{"no_defaults"}
defined $self->{"displayname_defaults"}
Truth table0%0/3
A or B
A= $opts{"no_defaults"}B= defined $self->{"displayname_defaults"}
| |||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $name = eval { | |||||||||||||||||||||||||||||||||||||
| 191 | 0 | _select_string( | |||||||||||||||||||||||||||||||||||||
| 192 | $policies, | ||||||||||||||||||||||||||||||||||||||
| 193 | $db->metadata(tag => $self, relation => $asi, no_type => [ | ||||||||||||||||||||||||||||||||||||||
| 194 | @identifier_types, | ||||||||||||||||||||||||||||||||||||||
| 195 | $wk->uuid, $wk->oid, $wk->uri, | ||||||||||||||||||||||||||||||||||||||
| 196 | ])->collect('data', skip_died => 1), | ||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||
| 198 | }; | ||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return $self->{displayname_defaults} = $name if defined($name) && length($name); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $name = eval {$self->ise}; | |||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return $self->{displayname_defaults} = $name if defined($name) && length($name); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return $self->{displayname} if defined $self->{displayname}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | unless ($opts{no_defaults}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | return $self->{displayname_defaults} if defined $self->{displayname_defaults}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return 'no name'; | |||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | 0 | croak 'No displayname found'; | |||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub displaycolour { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
displaycolour: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if (exists $self->{displaycolour}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return $self->{displaycolour} if defined $self->{displaycolour}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 222 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 223 | } else { | ||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $wk = $db->wk; | |||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->{displaycolour} = undef; # set to undef early so we can safely recurse. | |||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||
| 229 | 0 | foreach my $relation ( | |||||||||||||||||||||||||||||||||||||
| 230 | [qw(displaycolour)], | ||||||||||||||||||||||||||||||||||||||
| 231 | [qw(has_colour_value)], | ||||||||||||||||||||||||||||||||||||||
| 232 | [qw(wd_sRGB_colour_hex_triplet)] | ||||||||||||||||||||||||||||||||||||||
| 233 | ) { | ||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $relation = [grep {defined} map {eval{$wk->_call($_)}} @{$relation}]; | |||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | next unless scalar @{$relation}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $colour = eval { | |||||||||||||||||||||||||||||||||||||
| 237 | 0 | ($db->metadata(tag => $self, relation => $relation)->collect('data', skip_died => 1))[0], | |||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | return $self->{displaycolour} = $colour if defined($colour); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||
| 242 | 0 | foreach my $relation ( | |||||||||||||||||||||||||||||||||||||
| 243 | [qw(displaycolour)], | ||||||||||||||||||||||||||||||||||||||
| 244 | [qw(primary_colour)], | ||||||||||||||||||||||||||||||||||||||
| 245 | [qw(also_shares_colour)], | ||||||||||||||||||||||||||||||||||||||
| 246 | ) { | ||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $relation = [grep {defined} map {eval{$wk->_call($_)}} @{$relation}]; | |||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | next unless scalar @{$relation}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $colour = eval { | |||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | ($db->relation(tag => $self, relation => $relation)->collect(sub {$_[0]->related->displaycolour}, skip_died => 1))[0], | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | return $self->{displaycolour} = $colour if defined($colour); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | return $self->{displaycolour} if defined $self->{displaycolour}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 257 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub icontext { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
icontext: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (exists $self->{icontext}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return $self->{icontext} if defined $self->{icontext}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 267 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $wk = $db->wk; | |||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $self->{icontext} = undef; # set to undef as a default. | |||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | 0 | foreach my $relation ( | |||||||||||||||||||||||||||||||||||||
| 275 | [qw(tagpool_tag_icontext)], | ||||||||||||||||||||||||||||||||||||||
| 276 | [qw(wd_unicode_character)], | ||||||||||||||||||||||||||||||||||||||
| 277 | ) { | ||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $relation = [grep {defined} map {eval{$wk->_call($_)}} @{$relation}]; | |||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | next unless scalar @{$relation}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $icontext = eval { | |||||||||||||||||||||||||||||||||||||
| 281 | 0 | ($db->metadata(tag => $self, relation => $relation)->collect('data', skip_died => 1))[0], | |||||||||||||||||||||||||||||||||||||
| 282 | }; | ||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return $self->{icontext} = $icontext if defined($icontext) && length($icontext); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $icontext and length $icontext
MC/DC0%0/2
defined $icontext and length $icontext
defined $icontext
length $icontext
Truth table0%0/3
A and B
A= defined $icontextB= length $icontext
| |||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||
| 286 | # TODO: This should be extended to all roles: | ||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ((defined(my $tagpool_type_icontext = eval {$wk->tagpool_type_icontext}))) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $relation = [grep {defined} map {eval{$wk->_call($_)}} qw(has_type)]; | |||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (scalar @{$relation}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $icontext = ($db->metadata( | |||||||||||||||||||||||||||||||||||||
| 292 | tag => $db->relation(tag => $self, relation => $relation)->collect('related', return_ref => 1), | ||||||||||||||||||||||||||||||||||||||
| 293 | relation => $tagpool_type_icontext | ||||||||||||||||||||||||||||||||||||||
| 294 | )->collect('data', skip_died => 1))[0]; | ||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | return $self->{icontext} = $icontext if defined($icontext) && length($icontext); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $icontext and length $icontext
MC/DC0%0/2
defined $icontext and length $icontext
defined $icontext
length $icontext
Truth table0%0/3
A and B
A= defined $icontextB= length $icontext
| |||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | return $self->{icontext} if defined $self->{icontext}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 302 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if (exists $self->{description}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | return $self->{description} if defined $self->{description}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 312 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 313 | } else { | ||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $wk = $db->wk; | |||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->{description} = undef; # set to undef as a default. | |||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||
| 319 | 0 | foreach my $relation ( | |||||||||||||||||||||||||||||||||||||
| 320 | [qw(also_has_description)], | ||||||||||||||||||||||||||||||||||||||
| 321 | [qw(tagpool_description)], | ||||||||||||||||||||||||||||||||||||||
| 322 | ) { | ||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $relation = [grep {defined} map {eval{$wk->_call($_)}} @{$relation}]; | |||||||||||||||||||||||||||||||||||||
| 324 | 0 | ($self->{description}) = $db->metadata(tag => $self, relation => $relation)->collect('data', skip_died => 1); | |||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | last if defined $self->{description}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return $self->{description} if defined $self->{description}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | return $opts{default} if exists $opts{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 330 | 0 | croak 'No value found'; | |||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub cloudlet { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cloudlet: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my ($self, $which) = @_; | |||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my $cloudlets = $self->{cloudlets} //= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"cloudlets"} //= {}
MC/DC0%0/1
$self->{"cloudlets"} //= {}
$self->{"cloudlets"}
Truth table0%0/2
A
A= $self->{"cloudlets"}
| |||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if (defined $cloudlets->{$which}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $cloudlets->{$which}; | |||||||||||||||||||||||||||||||||||||
| 341 | } else { | ||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $wk = $self->db->wk; | |||||||||||||||||||||||||||||||||||||
| 343 | 0 | my %opts = ( | |||||||||||||||||||||||||||||||||||||
| 344 | tag => $self, | ||||||||||||||||||||||||||||||||||||||
| 345 | indirect => [ | ||||||||||||||||||||||||||||||||||||||
| 346 | $wk->specialises, | ||||||||||||||||||||||||||||||||||||||
| 347 | ], | ||||||||||||||||||||||||||||||||||||||
| 348 | ); | ||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ($which eq 'roles') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 351 | $opts{direct} = [ | ||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $wk->has_type, | |||||||||||||||||||||||||||||||||||||
| 353 | $wk->also_has_role, | ||||||||||||||||||||||||||||||||||||||
| 354 | ]; | ||||||||||||||||||||||||||||||||||||||
| 355 | } elsif ($which eq 'flags') { | ||||||||||||||||||||||||||||||||||||||
| 356 | $opts{direct} = [ | ||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $wk->flagged_as, | |||||||||||||||||||||||||||||||||||||
| 358 | ]; | ||||||||||||||||||||||||||||||||||||||
| 359 | } elsif ($which eq 'specialises') { | ||||||||||||||||||||||||||||||||||||||
| 360 | $opts{direct} = [ | ||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $wk->specialises, | |||||||||||||||||||||||||||||||||||||
| 362 | ]; | ||||||||||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||||||||
| 364 | 0 | croak 'Unknown cloudlet'; | |||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | 0 | return $cloudlets->{$which} = $self->db->_load_cloudlet(%opts); | |||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | sub has_role { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
has_role: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($self, $op, $list, @opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $cl = $self->cloudlet('roles'); | |||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | croak 'Stray options passed' if scalar @opts; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | $list = [$list] unless ref($list) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 380 | 0 | foreach my $ent (@{$list}) { | |||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | $ent = $ent->as(__PACKAGE__, db => $db) unless $ent->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ($op eq 'any') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | return any {$cl->is_entry($_)} @{$list}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 386 | } elsif ($op eq 'all') { | ||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | return all {$cl->is_entry($_)} @{$list}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 388 | } else { | ||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ...; | |||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||
| 393 | # ---- Private helpers ---- | ||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my ($pkg, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||
| 398 | 0 | return bless \%opts, $pkg; | |||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | sub _query { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_query: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||
| 403 | 0 | return $self->db->_query($name); | |||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | sub _get_data { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_data: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my ($self, $name, @args) = @_; | |||||||||||||||||||||||||||||||||||||
| 408 | 0 | return $self->db->_get_data($name, @args); | |||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | sub _select_string { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_string: not called CC=42 SCAR=75.0
| |||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my ($policies, @strings) = @_; | |||||||||||||||||||||||||||||||||||||
| 413 | 0 | my %res = map {$_ => 0} @strings; | |||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | return undef unless scalar @strings; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||
| 417 | 0 | foreach my $policy (@{$policies}) { | |||||||||||||||||||||||||||||||||||||
| 418 | 0 | foreach my $first (@strings) { | |||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ($policy eq 'upper') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | $res{$first} += $first =~ /\p{upper}/ ? 1 : -1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 421 | } elsif ($policy eq 'lower') { | ||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | $res{$first} += $first !~ /\p{upper}/ ? 1 : -1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 423 | } elsif ($policy eq 'space') { | ||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if ($first =~ /\s/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 426 | } elsif ($first =~ /[-_]/) { | ||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $res{$first}--; | |||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||
| 429 | } elsif ($policy eq 'dash') { | ||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($first =~ /[-_]/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 432 | } elsif ($first =~ /\s/) { | ||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $res{$first}--; | |||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||
| 435 | } elsif ($policy eq 'nospace') { | ||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if ($first =~ /\s/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $res{$first} -= 64; | |||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||
| 439 | } elsif ($policy eq 'noupper') { | ||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if ($first =~ /\p{upper}/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $res{$first} -= 64; | |||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||
| 443 | ▶ | } elsif ($policy eq 'long' || $policy eq 'short') { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$policy eq "long" or $policy eq "short"
MC/DC0%0/2
$policy eq "long" or $policy eq "short"
$policy eq "long"
$policy eq "short"
Truth table0%0/3
A or B
A= $policy eq "long"B= $policy eq "short"
| |||||||||||||||||||||||||||||||||||||||
| 444 | 0 | foreach my $second (@strings) { | |||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | next if $first eq $second; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $lf = length($first); | |||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $ls = length($second); | |||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | ($lf, $ls) = ($ls, $lf) if $policy eq 'short'; # swap. | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if ($lf > $ls) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 451 | 0 | $res{$second}--; | |||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||
| 454 | } elsif ($policy eq 'british') { | ||||||||||||||||||||||||||||||||||||||
| 455 | 0 | foreach my $second (@strings) { | |||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | next if $first eq $second; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if (fc($first =~ tr/z/s/r) eq fc($second =~ tr/z/s/r)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | my $fx = scalar($first =~ /(z)/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar $first =~ /(z)/gu || 0
MC/DC0%0/1
scalar $first =~ /(z)/gu || 0
scalar $first =~ /(z)/gu
Truth table0%0/2
A
A= scalar $first =~ /(z)/gu
| |||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | my $sx = scalar($second =~ /(z)/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar $second =~ /(z)/gu || 0
MC/DC0%0/1
scalar $second =~ /(z)/gu || 0
scalar $second =~ /(z)/gu
Truth table0%0/2
A
A= scalar $second =~ /(z)/gu
| |||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if ($fx < $sx) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 462 | 0 | $res{$second}--; | |||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if (fc(($first.' ') =~ s/er\b/re/gr) eq fc(($second.' ') =~ s/er\b/re/gr)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | my $fx = scalar(($first.' ') =~ /(er)\b/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar(($first . ' ') =~ /(er)\b/gu) || 0
MC/DC0%0/1
scalar(($first . ' ') =~ /(er)\b/gu) || 0
scalar(($first . ' ') =~ /(er)\b/gu)
Truth table0%0/2
A
A= scalar(($first . ' ') =~ /(er)\b/gu)
| |||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | my $sx = scalar(($second.' ') =~ /(er)\b/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar(($second . ' ') =~ /(er)\b/gu) || 0
MC/DC0%0/1
scalar(($second . ' ') =~ /(er)\b/gu) || 0
scalar(($second . ' ') =~ /(er)\b/gu)
Truth table0%0/2
A
A= scalar(($second . ' ') =~ /(er)\b/gu)
| |||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($fx < $sx) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 470 | 0 | $res{$second}--; | |||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if (fc($first =~ s/ou/o/gr) eq fc($second =~ s/ou/o/gr)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | my $fx = scalar($first =~ /(ou)/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar $first =~ /(ou)/gu || 0
MC/DC0%0/1
scalar $first =~ /(ou)/gu || 0
scalar $first =~ /(ou)/gu
Truth table0%0/2
A
A= scalar $first =~ /(ou)/gu
| |||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | my $sx = scalar($second =~ /(ou)/g) || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
scalar $second =~ /(ou)/gu || 0
MC/DC0%0/1
scalar $second =~ /(ou)/gu || 0
scalar $second =~ /(ou)/gu
Truth table0%0/2
A
A= scalar $second =~ /(ou)/gu
| |||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($fx > $sx) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $res{$first}++; | |||||||||||||||||||||||||||||||||||||
| 478 | 0 | $res{$second}--; | |||||||||||||||||||||||||||||||||||||
| 479 | } elsif ($fx < $sx) { # this one is not symetric, so we need it the other way around as well | ||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $res{$first}--; | |||||||||||||||||||||||||||||||||||||
| 481 | 0 | $res{$second}++; | |||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | if (fc($first =~ s/gray/grey/gir) eq fc($second)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $res{$first}--; | |||||||||||||||||||||||||||||||||||||
| 486 | 0 | $res{$second}++; | |||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||
| 489 | } else { | ||||||||||||||||||||||||||||||||||||||
| 490 | 0 | die 'Bad policy'; | |||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||
| 495 | #say '#++ Dump: [', join(' ', @{$policies}), ']', map {sprintf(' "%s" => %d', $_, $res{$_})} sort {$res{$b} <=> $res{$a} || $a cmp $b} @strings; | ||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return (sort {$res{$b} <=> $res{$a} || $a cmp $b} @strings)[0]; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$res{$b} <=> $res{$a} || $a cmp $b
MC/DC0%0/2
$res{$b} <=> $res{$a} || $a cmp $b
$res{$b} <=> $res{$a}
$a cmp $b
Truth table0%0/3
A || B
A= $res{$b} <=> $res{$a}B= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub attribute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my ($self, $attribute, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if ($attribute =~ /^display/ || $attribute eq 'icontext') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attribute =~ /^display/u or $attribute eq "icontext"
MC/DC0%0/2
$attribute =~ /^display/u or $attribute eq "icontext"
$attribute =~ /^display/u
$attribute eq "icontext"
Truth table0%0/3
A or B
A= $attribute =~ /^display/uB= $attribute eq "icontext"
| |||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my $func = $self->can($attribute); | |||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | return $self->$func(%opts) if defined $func; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | $self->{attribute} //= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"attribute"} //= {}
MC/DC0%0/1
$self->{"attribute"} //= {}
$self->{"attribute"}
Truth table0%0/2
A
A= $self->{"attribute"}
| |||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | if (exists $opts{set}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $self->{attribute}{$attribute} = $opts{set}; | |||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | unless (exists $self->{attribute}{$attribute}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 515 | # TODO: try to calculate here. | ||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return $self->{attribute}{$attribute}; | |||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | sub clear_cache { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_cache: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my ($self, @opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 524 | 0 | $self->SUPER::clear_cache(@opts); | |||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||
| 526 | 0 | delete $self->{$_} foreach qw(displayname displaycolour icontext description cloudlets); | |||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||
| 528 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||
| 531 | 4 | 1; | |||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||
| 533 | __END__ | ||||||||||||||||||||||||||||||||||||||