| 1 | # Copyright (c) 2024-2025 Philipp Schafft | ||
| 2 | |||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||
| 4 | |||
| 5 | # ABSTRACT: module for reading and writing ValueFile files | ||
| 6 | |||
| 7 | package File::ValueFile; | ||
| 8 | |||
| 9 | use v5.10; | ||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | use Carp; | ||
| 14 | use Data::Identifier v0.08; | ||
| 15 | use parent 'Data::Identifier::Interface::Known'; | ||
| 16 | |||
| 17 | our $VERSION = v0.10; | ||
| 18 | |||
| 19 | my @wellknown = ( | ||
| 20 | Data::Identifier->new(uuid => '54bf8af4-b1d7-44da-af48-5278d11e8f32', displayname => 'ValueFile'), | ||
| 21 | Data::Identifier->new(uuid => 'e5da6a39-46d5-48a9-b174-5c26008e208e', displayname => 'tagpool-source-format'), | ||
| 22 | Data::Identifier->new(uuid => '11431b85-41cd-4be5-8d88-a769ebbd603f', displayname => 'tagpool-directory-info-format'), | ||
| 23 | Data::Identifier->new(uuid => 'afdb46f2-e13f-4419-80d7-c4b956ed85fa', displayname => 'tagpool-taglist-format-v1'), | ||
| 24 | Data::Identifier->new(uuid => '25990339-3913-4b5a-8bcf-5042ef6d8b5e', displayname => 'tagpool-httpd-htdirectories-format'), | ||
| 25 | Data::Identifier->new(uuid => '5a1895b8-61f1-4ce1-a44f-1a239b7d9de7', displayname => 'tagpool-source-format-hybrid'), | ||
| 26 | Data::Identifier->new(uuid => 'f06c2226-b33e-48f2-9085-cd906a3dcee0', displayname => 'tagpool-source-format-modern-limited'), | ||
| 27 | Data::Identifier->new(uuid => '1c71f5b1-216d-4a9b-81a1-54dc22d8a067', displayname => 'tagpool-source-format-modern-full'), | ||
| 28 | Data::Identifier->new(uuid => '7e5d56d4-98e6-4205-89c0-763e1d729531', displayname => 'utf-8-marker'), | ||
| 29 | Data::Identifier->new(uuid => '2ec67bbe-4698-4a0c-921d-1f0951923ee6', displayname => 'dot-repeat-marker'), | ||
| 30 | ); | ||
| 31 | |||
| 32 | $_->register foreach @wellknown; | ||
| 33 | |||
| 34 | my %_is_utf8 = ( | ||
| 35 | (map {$_ => undef} ( | ||
| 36 | 'e5da6a39-46d5-48a9-b174-5c26008e208e', # tagpool-source-format | ||
| 37 | '11431b85-41cd-4be5-8d88-a769ebbd603f', # tagpool-directory-info-format | ||
| 38 | '7e5d56d4-98e6-4205-89c0-763e1d729531', # utf-8-marker | ||
| 39 | )), | ||
| 40 | ); | ||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | sub add_utf8_marker { | ||
| 46 | my ($pkg, $class, $id) = @_; | ||
| 47 | |||
| 48 | if (!defined($class) || !defined($id)) { | ||
| 49 | croak 'Class or identifier not defined'; | ||
| 50 | } | ||
| 51 | |||
| 52 | if ($class ne 'format' && $class ne 'feature') { | ||
| 53 | croak 'Class given with an unsupported value: '.$class; | ||
| 54 | } | ||
| 55 | |||
| 56 | $_is_utf8{Data::Identifier->new(from => $id)->ise} = undef; | ||
| 57 | } | ||
| 58 | |||
| 59 | # ---- Private helpers ---- | ||
| 60 | |||
| 61 | sub _is_utf8 { | ||
| 62 | my ($pkg, $id) = @_; | ||
| 63 | return exists $_is_utf8{Data::Identifier->new(from => $id)->ise}; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub _known_provider { | ||
| 67 | my ($pkg, $class, %opts) = @_; | ||
| 68 | croak 'Unsupported options passed' if scalar(keys %opts); | ||
| 69 | return (\@wellknown, rawtype => 'uuid') if $class eq ':all'; | ||
| 70 | croak 'Unsupported class'; | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ |