| 1 | # Copyright (c) 2026 Philipp Schafft | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | # ABSTRACT: Work with Gamebook data in TagDBs | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | package Data::TagDB::Plugin::Gamebook; | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use Data::TagDB::Interface::Plugin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Data::TagDB::Relation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | ▶ | use Data::TagDB::Metadata; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | ▶ | use Data::TagDB::Cloudlet; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 1 | ▶ | use Data::TagDB::Tag; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 1 | ▶ | use Data::Identifier; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use parent 'Data::Identifier::Interface::Known'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | use Data::TagDB::Plugin::Gamebook::Exit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | our $VERSION = v0.02; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | my %_wk = map {$_->tagname =~ tr/-/_/r =~ s/^gamebook_/gb_/r => $_->register} ( | |||||||||||||||||||
| 28 | Data::Identifier->new(uuid => '7f265548-81dc-4280-9550-1bd0aa4bf748', tagname => 'has-type'), | ||||||||||||||||||||
| 29 | Data::Identifier->new(uuid => 'd2750351-aed7-4ade-aa80-c32436cc6030', tagname => 'also-has-role'), | ||||||||||||||||||||
| 30 | Data::Identifier->new(uuid => '923b43ae-a50e-4db3-8655-ed931d0dd6d4', tagname => 'specialises'), | ||||||||||||||||||||
| 31 | Data::Identifier->new(uuid => '10a65258-237f-45f5-9d84-7287d62dcbb5', tagname => 'gamebook-application-context'), | ||||||||||||||||||||
| 32 | Data::Identifier->new(uuid => 'bad2f56f-5ea7-4725-bcd0-60be71cf3768', tagname => 'gamebook-valuefile-format'), | ||||||||||||||||||||
| 33 | Data::Identifier->new(uuid => '3c9f48a4-5c35-49d0-8908-1c9e1853fa1e', tagname => 'gamebook-type'), | ||||||||||||||||||||
| 34 | Data::Identifier->new(uuid => '4cb471e3-c921-44a6-9fba-3d19f45aab35', tagname => 'gamebook-vocabulary'), | ||||||||||||||||||||
| 35 | Data::Identifier->new(uuid => '330436f2-91f1-4422-8f0a-4b804a37f101', tagname => 'gamebook-vocabulary-base'), | ||||||||||||||||||||
| 36 | Data::Identifier->new(uuid => 'ef7b2199-7cca-4efb-96bb-d18795546973', tagname => 'gamebook-role-marker'), | ||||||||||||||||||||
| 37 | Data::Identifier->new(uuid => '1357f4c9-0419-4493-8d2c-97c6a40a9bc9', tagname => 'gamebook-has-title'), | ||||||||||||||||||||
| 38 | Data::Identifier->new(uuid => 'def9538d-b193-4144-9389-008f3fb23633', tagname => 'gamebook-has-text'), | ||||||||||||||||||||
| 39 | Data::Identifier->new(uuid => '2b3b7539-4dc2-43d1-afb9-974cda48ae82', tagname => 'gamebook-has-content'), | ||||||||||||||||||||
| 40 | Data::Identifier->new(uuid => '564e3dc6-aef7-4103-863a-aa88dd04204c', tagname => 'gamebook-index-listed'), | ||||||||||||||||||||
| 41 | Data::Identifier->new(uuid => 'c333b55a-77e6-4cda-bf36-73f6e99a20bc', tagname => 'gamebook-pagelike'), | ||||||||||||||||||||
| 42 | Data::Identifier->new(uuid => '82b47919-bc0c-47e0-953e-81f6c5833860', tagname => 'gamebook-eventlike'), | ||||||||||||||||||||
| 43 | Data::Identifier->new(uuid => 'c9eec21d-a9b0-4818-99fe-fa4d24c43352', tagname => 'gamebook-book'), | ||||||||||||||||||||
| 44 | Data::Identifier->new(uuid => '316850a0-abf1-4b07-abeb-1386c2f19a0f', tagname => 'gamebook-story'), | ||||||||||||||||||||
| 45 | Data::Identifier->new(uuid => '39a3b6ae-0388-4ae5-97a6-1938b7a41db7', tagname => 'gamebook-scene'), | ||||||||||||||||||||
| 46 | Data::Identifier->new(uuid => '148c356a-ce5e-4a72-9e1e-7f30d3d38e21', tagname => 'gamebook-exit'), | ||||||||||||||||||||
| 47 | Data::Identifier->new(uuid => 'f66e0cd2-852e-4a01-8c52-881430f4d8b3', tagname => 'gamebook-object-group'), | ||||||||||||||||||||
| 48 | Data::Identifier->new(uuid => '1acdb1f1-1b0f-42ba-9de7-a8f4e0f4d6c1', tagname => 'gamebook-relation'), | ||||||||||||||||||||
| 49 | Data::Identifier->new(uuid => '8b919a2a-1dee-458d-b2fe-f646573ad4e6', tagname => 'gamebook-title'), | ||||||||||||||||||||
| 50 | Data::Identifier->new(uuid => '0678cfe2-1386-43db-86a9-6c491b2df64c', tagname => 'gamebook-text'), | ||||||||||||||||||||
| 51 | Data::Identifier->new(uuid => 'ee451ce6-fa8e-4879-ad02-18e480ee3da7', tagname => 'gamebook-role'), | ||||||||||||||||||||
| 52 | Data::Identifier->new(uuid => '26541fcc-3248-48c8-a157-efb263b5d719', tagname => 'gamebook-contains'), | ||||||||||||||||||||
| 53 | Data::Identifier->new(uuid => '9bfe73f4-c3ca-464c-8e46-548931aa1571', tagname => 'gamebook-target'), | ||||||||||||||||||||
| 54 | Data::Identifier->new(uuid => '64df20b4-3a22-4054-881c-e750cdabf850', tagname => 'gamebook-direction'), | ||||||||||||||||||||
| 55 | Data::Identifier->new(uuid => '103769a6-efdc-4088-a128-fc655da2d2ae', tagname => 'gamebook-available-context'), | ||||||||||||||||||||
| 56 | Data::Identifier->new(uuid => 'd8273dea-3cb2-48f1-8f50-559bbb12bf69', tagname => 'gamebook-scroll-thru'), | ||||||||||||||||||||
| 57 | Data::Identifier->new(uuid => '53b7716b-65b1-4268-88e5-81f4c997f0ea', tagname => 'gamebook-direct-speech'), | ||||||||||||||||||||
| 58 | Data::Identifier->new(uuid => 'd4fad62f-7e02-49ac-b9c6-4417aca0c45e', tagname => 'gamebook-direction-marker'), | ||||||||||||||||||||
| 59 | Data::Identifier->new(uuid => '95fc948e-b9a3-46b8-a120-68858df1c96e', tagname => 'gamebook-uses-vocabulary'), | ||||||||||||||||||||
| 60 | Data::Identifier->new(uuid => 'f6c29c2e-d667-44fb-b1fb-4b18e1a5ef7d', tagname => 'gamebook-uses-cache-vocabulary'), | ||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # ---- Private helpers ---- | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | sub plugin_attach { | ||||||||||||||||||
|
Subroutine
plugin_attach: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 67 | 0 | my ($pkg, $db, $conf, %opts) = @_; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | return { | ||||||||||||||||||||
| 70 | tag_attributes => { | ||||||||||||||||||||
| 71 | title => { | ||||||||||||||||||||
| 72 | 0 | ▶ | get => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 73 | 0 | my ($tag) = @_; | |||||||||||||||||||
| 74 | 0 | my Data::TagDB $db = $tag->db; | |||||||||||||||||||
| 75 | 0 | my $v; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | foreach my $wk (map {$_wk{$_}} qw(gb_title)) { | |||||||||||||||||||
| 78 | 0 | ▶ | $db->metadata(tag => $tag, relation => $db->tag_by_id($wk))->foreach(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 79 | 0 | my Data::TagDB::Metadata $link = $_[0]; | |||||||||||||||||||
| 80 | 0 | ▶ | $v //= $link->data; | ||||||||||||||||||
|
Condition0%0/3
$v //= $link->data
MC/DC0%0/2
$v //= $link->data
$v
$link->data
Truth table0%0/3
A //= B
A= $vB= $link->data
| |||||||||||||||||||||
| 81 | 0 | }); | |||||||||||||||||||
| 82 | 0 | ▶ | last if defined $v; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | unless (defined $v) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | ▶ | $db->relation(tag => $tag, relation => $db->tag_by_id($_wk{gb_target}))->foreach(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 87 | 0 | my Data::TagDB::Relation $link = $_[0]; | |||||||||||||||||||
| 88 | 0 | ▶ | $v //= $link->related->get('Data::TagDB::Plugin::Gamebook#title', default => undef); | ||||||||||||||||||
|
Condition0%0/3
$v //= $link->related->get("Data::TagDB::Plugin::Gamebook#title", "default", undef)
MC/DC0%0/2
$v //= $link->related->get("Data::TagDB::Plugin::Gamebook#title", "default", undef)
$v
$link->related->get("Data::TagDB::Plugin::Gamebook#title", "default", undef)
Truth table0%0/3
A //= B
A= $vB= $link->related->get("Data::TagDB::Plugin::Gamebook#title", "default", undef)
| |||||||||||||||||||||
| 89 | 0 | }); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | return [$v], no_value => !defined($v); | |||||||||||||||||||
| 93 | }, | ||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||
| 95 | text => { | ||||||||||||||||||||
| 96 | 0 | ▶ | get => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 97 | 0 | my ($tag) = @_; | |||||||||||||||||||
| 98 | 0 | my Data::TagDB $db = $tag->db; | |||||||||||||||||||
| 99 | 0 | my @v; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | $db->metadata(tag => $tag, relation => $db->tag_by_id($_wk{gb_text}))->foreach(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 102 | 0 | my Data::TagDB::Metadata $link = $_[0]; | |||||||||||||||||||
| 103 | 0 | push(@v, $link->data); | |||||||||||||||||||
| 104 | 0 | }); | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | return \@v; | |||||||||||||||||||
| 107 | }, | ||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||
| 109 | exit => { | ||||||||||||||||||||
| 110 | 0 | ▶ | get => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 111 | 0 | my ($tag) = @_; | |||||||||||||||||||
| 112 | 0 | my Data::TagDB $db = $tag->db; | |||||||||||||||||||
| 113 | 0 | my Data::TagDB::Tag $exit = $db->tag_by_id($_wk{gb_exit}); | |||||||||||||||||||
| 114 | 0 | my @v; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 0 | ▶ | $db->relation(tag => $tag, relation => $db->tag_by_id($_wk{gb_contains}))->foreach(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 117 | 0 | my Data::TagDB::Relation $link = $_[0]; | |||||||||||||||||||
| 118 | 0 | my Data::TagDB::Tag $related = $link->related; | |||||||||||||||||||
| 119 | 0 | my Data::TagDB::Cloudlet $roles = $related->cloudlet('roles'); | |||||||||||||||||||
| 120 | 0 | ▶ | push(@v, Data::TagDB::Plugin::Gamebook::Exit->_new($related)) if $roles->is_entry($exit); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 0 | }); | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | return \@v; | |||||||||||||||||||
| 124 | }, | ||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||
| 127 | 0 | }; | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | ▶ | sub _known_provider { | ||||||||||||||||||
|
Subroutine
_known_provider: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 131 | 0 | my ($pkg, $class, %opts) = @_; | |||||||||||||||||||
| 132 | 0 | ▶ | croak 'Unsupported options passed' if scalar(keys %opts); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | ▶ | return ([values %_wk]) if $class eq ':all'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 0 | croak 'Unsupported class'; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||