File Coverage

lib/Data/TagDB/Metadata.pm
Criterion Covered Total %
statement 14 31 45.1
branch 0 4 0.0
condition 0 12 0.0
subroutine 5 11 45.4
pod 4 6 66.6
total 23 64 35.9


line stmt bran cond sub pod time code
1             # Copyright (c) 2024-2025 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::Metadata;
8              
9 1     1   14 use v5.10;
  1         5  
10 1     1   7 use strict;
  1         2  
  1         39  
11 1     1   6 use warnings;
  1         2  
  1         53  
12              
13 1     1   6 use parent 'Data::TagDB::Link';
  1         2  
  1         6  
14              
15 1     1   96 use Carp;
  1         2  
  1         501  
16              
17             our $VERSION = v0.12;
18              
19              
20              
21             sub type {
22 0     0 1   my ($self) = @_;
23 0           return $self->{type};
24             }
25              
26             sub encoding {
27 0     0 1   my ($self) = @_;
28 0           return $self->{encoding};
29             }
30              
31             sub type_evaluated {
32 0     0 0   my ($self) = @_;
33 0   0       return $self->{type_evaluated} //= ($self->type // $self->db->_default_type($self->relation));
      0        
34             }
35              
36             sub encoding_evaluated {
37 0     0 0   my ($self) = @_;
38 0   0       return $self->{encoding_evaluated} //= ($self->encoding // $self->db->_default_encoding($self->type_evaluated));
      0        
39             }
40              
41              
42             sub data_raw {
43 0     0 1   my ($self) = @_;
44 0           return $self->{data_raw};
45             }
46              
47              
48             sub data {
49 0     0 1   my ($self) = @_;
50 0 0         if (exists $self->{data}) {
51 0           return $self->{data};
52             } else {
53 0           eval {
54 0           $self->{data} = $self->db->_get_decoder($self)->($self);
55             };
56 0 0         croak 'Cannot decode' unless exists $self->{data};
57 0           return $self->{data};
58             }
59             }
60              
61             1;
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Data::TagDB::Metadata - Work with Tag databases
72              
73             =head1 VERSION
74              
75             version v0.12
76              
77             =head1 SYNOPSIS
78              
79             use Data::TagDB;
80              
81             Package of Metadata. Inherits from L<Data::TagDB::Link>.
82              
83             =head1 METHODS
84              
85             =head2 type, encoding
86              
87             my Data::TagDB::Tag $db = $link->type;
88             my Data::TagDB::Tag $db = $link->encoding;
89              
90             Returns the corresponding type, or encoding. Returns undef if not set.
91              
92             =head2 data_raw
93              
94             my $raw = $link->data_raw;
95              
96             Returns the raw data of the metadata.
97              
98             =head2 data
99              
100             my $data = $link->data;
101              
102             Returns the data in what is considered the most native form for Perl.
103             E.g. URIs are returned in with package L<URI>.
104              
105             This method requires a decoder to be installed for the given type and encoding.
106              
107             =head1 AUTHOR
108              
109             Philipp Schafft <lion@cpan.org>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>.
114              
115             This is free software, licensed under:
116              
117             The Artistic License 2.0 (GPL Compatible)
118              
119             =cut