| 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::Exporter; | ||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::ValueFile::Simple::Writer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | our $VERSION = v0.16; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use parent 'Data::TagDB::WeakBaseObject'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | FORMAT_TAGPOOL_SOURCE_FORMAT => 'e5da6a39-46d5-48a9-b174-5c26008e208e', | |||||||||||||||||||||||||||
| 22 | FORMAT_TAGPOOL_TAGLIST_V1 => 'afdb46f2-e13f-4419-80d7-c4b956ed85fa', | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | FEATURE_MODERN_LIMITED => 'f06c2226-b33e-48f2-9085-cd906a3dcee0', | ||||||||||||||||||||||||||||
| 25 | 1 | }; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub db { | ||||||||||||||||||||||||||
|
Subroutine
db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 31 | 0 | return $self->{db}; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub tag { | ||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ($self, $tag, %opts) = @_; | |||||||||||||||||||||||||||
| 37 | 0 | my $format = $self->{format}; | |||||||||||||||||||||||||||
| 38 | 0 | my Data::TagDB $db = $self->db; | |||||||||||||||||||||||||||
| 39 | 0 | my $ise = $tag->ise; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return if exists $self->{tags_done}->{$ise}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{tags_done}->{$ise} = undef; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($format eq FORMAT_TAGPOOL_SOURCE_FORMAT) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 45 | 0 | my File::ValueFile::Simple::Writer $writer = $self->_valuefile_handle; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | $writer->write; | |||||||||||||||||||||||||||
| 48 | 0 | $writer->write_tag_ise($tag); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless ($opts{skip_metadata}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $db->metadata(tag => $tag)->foreach(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 0 | $writer->write_tag_metadata($_[0]); | |||||||||||||||||||||||||||
| 52 | 0 | }); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | unless ($opts{skip_relation}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $db->relation(tag => $tag)->foreach(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 56 | 0 | $writer->write_tag_relation($_[0]); | |||||||||||||||||||||||||||
| 57 | 0 | }); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } elsif ($format eq FORMAT_TAGPOOL_TAGLIST_V1) { | ||||||||||||||||||||||||||||
| 60 | 0 | my File::ValueFile::Simple::Writer $writer = $self->_valuefile_handle; | |||||||||||||||||||||||||||
| 61 | 0 | $writer->write(tag => $tag); | |||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||
| 63 | 0 | croak 'Bad format'; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub metadata { | ||||||||||||||||||||||||||
|
Subroutine
metadata: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $link, %opts) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | my $format = $self->{format}; | |||||||||||||||||||||||||||
| 71 | 0 | my Data::TagDB $db = $self->db; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($format eq FORMAT_TAGPOOL_SOURCE_FORMAT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | my File::ValueFile::Simple::Writer $writer = $self->_valuefile_handle; | |||||||||||||||||||||||||||
| 75 | 0 | $writer->write_tag_metadata($link); | |||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||
| 77 | 0 | croak 'Bad format'; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub relation { | ||||||||||||||||||||||||||
|
Subroutine
relation: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my ($self, $link, %opts) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | my $format = $self->{format}; | |||||||||||||||||||||||||||
| 85 | 0 | my Data::TagDB $db = $self->db; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($format eq FORMAT_TAGPOOL_SOURCE_FORMAT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | my File::ValueFile::Simple::Writer $writer = $self->_valuefile_handle; | |||||||||||||||||||||||||||
| 89 | 0 | $writer->write_tag_relation($link); | |||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 0 | croak 'Bad format'; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # ---- Private helpers ---- | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub _new { | ||||||||||||||||||||||||||
|
Subroutine
_new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 98 | 0 | my ($pkg, @args) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | my $self = $pkg->SUPER::_new(@args); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $self->{format} //= FORMAT_TAGPOOL_SOURCE_FORMAT; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"format"} //= "e5da6a39-46d5-48a9-b174-5c26008e208e"
MC/DC0%0/1
$self->{"format"} //= "e5da6a39-46d5-48a9-b174-5c26008e208e"
$self->{"format"}
Truth table0%0/2
A
A= $self->{"format"}
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $self->{format} = $self->{format}->ise if ref $self->{format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $self->{tags_done} = {}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub _valuefile_handle { | ||||||||||||||||||||||||||
|
Subroutine
_valuefile_handle: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 110 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 111 | return $self->{_valuefile_handle} //= File::ValueFile::Simple::Writer->new( | ||||||||||||||||||||||||||||
| 112 | $self->{target}, | ||||||||||||||||||||||||||||
| 113 | format => $self->{format}, | ||||||||||||||||||||||||||||
| 114 | required_feature => [ | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $self->{format} eq FORMAT_TAGPOOL_SOURCE_FORMAT ? (FEATURE_MODERN_LIMITED) : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_valuefile_handle"} //= "File::ValueFile::Simple::Writer"->new($self->{"target"}, "format", $self->{"format"}, "required_feature", [$self->{"format"} eq "e5da6a39-46d5-48a9-b174-5c26008e208e" ? "f06c2226-b33e-48f2-9085-cd906a3dcee0" : ()])
MC/DC0%0/2
$self->{"_valuefile_handle"} //= "File::ValueFile::Simple::Writer"->new($self->{"target"}, "format", $self->{"format"}, "required_feature", [$self->{"format"} eq "e5da6a39-46d5-48a9-b174-5c26008e208e" ? "f06c2226-b33e-48f2-9085-cd906a3dcee0" : ()])
$self->{"_valuefile_handle"}
"File::ValueFile::Simple::Writer"->new($self->{"target"}, "format", $self->{"format"}, "required_feature", [$self->{"format"} eq "e5da6a39-46d5-48a9-b174-5c26008e208e" ? "f06c2226-b33e-48f2-9085-cd906a3dcee0" : ()])
Truth table0%0/3
A //= B
A= $self->{"_valuefile_handle"}B= "File::ValueFile::Simple::Writer"->new($self->{"target"}, "format", $self->{"format"}, "required_feature", [$self->{"format"} eq "e5da6a39-46d5-48a9-b174-5c26008e208e" ? "f06c2226-b33e-48f2-9085-cd906a3dcee0" : ()])
| |||||||||||||||||||||||||||||
| 116 | ], | ||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||