| 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::Cloudlet; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
13
|
use v5.16; |
|
|
1
|
|
|
|
|
23
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
43
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
80
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use Data::TagDB::Iterator; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
925
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = v0.12; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
0
|
|
|
0
|
1
|
|
my ($pkg, %opts) = @_; |
|
23
|
0
|
|
0
|
|
|
|
my $root = delete($opts{root}) // []; |
|
24
|
0
|
|
0
|
|
|
|
my $entry = delete($opts{entry}) // []; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
croak 'No database given' unless defined $opts{db}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
$root = [$root] unless ref($root) eq 'ARRAY'; |
|
29
|
0
|
0
|
|
|
|
|
$entry = [$entry] unless ref($entry) eq 'ARRAY'; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$opts{entries} = { |
|
32
|
0
|
|
|
|
|
|
(map {$_->dbid => undef} @{$entry}), |
|
|
0
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
(map {$_->dbid => 1} @{$root}), |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return bless \%opts, $pkg; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub db { |
|
41
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
42
|
0
|
|
|
|
|
|
return $self->{db}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub roots { |
|
47
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
48
|
0
|
|
|
|
|
|
my Data::TagDB $db = $self->db; |
|
49
|
0
|
|
|
|
|
|
my $entries = $self->{entries}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return map {$db->tag_by_dbid($_)} grep {$entries->{$_}} keys %{$entries}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub entries { |
|
56
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
57
|
0
|
|
|
|
|
|
my Data::TagDB $db = $self->db; |
|
58
|
0
|
|
|
|
|
|
my $entries = $self->{entries}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return map {$db->tag_by_dbid($_)} keys %{$entries}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub roots_iterator { |
|
65
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
66
|
0
|
|
|
|
|
|
my @entries = $self->roots; |
|
67
|
0
|
|
|
|
|
|
return Data::TagDB::Iterator->from_array(\@entries, db => $self->db); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub entries_iterator { |
|
72
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
73
|
0
|
|
|
|
|
|
my @entries = $self->entries; |
|
74
|
0
|
|
|
|
|
|
return Data::TagDB::Iterator->from_array(\@entries, db => $self->db); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_root { |
|
79
|
0
|
|
|
0
|
1
|
|
my ($self, $tag) = @_; |
|
80
|
0
|
|
|
|
|
|
return $self->{entries}{$tag->dbid}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub is_entry { |
|
85
|
0
|
|
|
0
|
1
|
|
my ($self, $tag) = @_; |
|
86
|
0
|
|
|
|
|
|
return exists $self->{entries}{$tag->dbid}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ---- Private helpers ---- |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=pod |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=encoding UTF-8 |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Data::TagDB::Cloudlet - Work with Tag databases |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
version v0.12 |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Data::TagDB; |
|
110
|
|
|
|
|
|
|
use Data::TagDB::Cloudlet; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $db = Data::TagDB->new(...); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my Data::TagDB::Cloudlet $cl = Data::TagDB::Cloudlet->new(db => $db, root => [...]); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This module implements cloudlets. A cloudlet is a collection of tags. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
In a cloudlet each tag can only be once. Each tag has a boolean attached that indices if it is a root tag. |
|
119
|
|
|
|
|
|
|
This is used to indicate if a tag is a first level member or was added by means of completion. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 METHODS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 new |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my Data::TagDB::Cloudlet $cl = Data::TagDB::Cloudlet->new(db => $db, root => [...]); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Creates a new cloudlet object. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The following options are supported: |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item C<db> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The database to use. This is required. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item C<root> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The root tag or tags. May be an arrayref of or single a L<Data::TagDB::Tag>. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item C<entry> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Additional tags that are not root tags. May be an arrayref of or single a L<Data::TagDB::Tag>. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 db |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my Data::TagDB $db = $cl->db; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Returns the current L<Data::TagDB> object. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 roots |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my @roots = $cl->roots; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns the list of root tags. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 entries |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my @entries = $cl->entries; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns the list of all entries. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 roots_iterator |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my Data::TagDB::Iterator $iter = $cl->roots_iterator; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Create an iterator for root entries. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 entries_iterator |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my Data::TagDB::Iterator $iter = $cl->entries_iterator; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Create an iterator for all entries. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 is_root |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $bool = $cl->is_root($tag); |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Returns whether or not a given tag is a root tag. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 is_entry |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $bool = $cl->is_entry($tag); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns whether or not a given tag is part of the cloudlet. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHOR |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Philipp Schafft <lion@cpan.org> |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This is free software, licensed under: |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |